3

I know there are a number of ways to prevent users from entering illegal input: disabling buttons, showing warnings, and other solutions that fit the domain of the problem. However, the usual practices in software and web apps do not feel right if we consider something very simple - for example, a calculator app for a smartphone. Here's the situation:

A user enters 5, 0, and / (this is a reverse Polish notation calculator). This translates to 5 / 0, and is thus an illegal operation. Now I could introduce a physical constraint (disable the / button in my app), ensuring that division by zero becomes impossible. However, this is not how actual calculators work. From what I remember, some of the common calculators return 0 in such a case or indicate an error somehow. And then - depending on how good the device is - the user can either recover from the error or has to reenter everything. This becomes a bit more complicated in the case of RPN calculators - the result of any operation is put on top of the operand stack so that the next operation can use that result right away. Therefore, returning NAN, for example, would mean that no operations can be performed until legal operands are entered. Returning 0 in this case sounds like a better idea, but what if it confuses the user into thinking that, e.g., sqrt(-1) = 0?

So my question is then as follows: what would be the most appropriate way of dealing with illegal operations in a simple calculator app for a smartphone? Would it make more sense to return 0 (sounds most reasonable), NAN (complicates things), or disable illegal operations (reasonable, yet deviates from user expectations and experiences with real calculators)?

4
  • is this comparable to a scientific or just a basic calculator? Commented Jan 24, 2012 at 18:25
  • Show Error. but provide recovery options such as access to history of recent results in order to be able to retrieve something on the stack that was calculated via multiple operations. Note that this would be useful in a calculator anyway! Commented Jan 24, 2012 at 18:47
  • @jberger basic.
    – user8597
    Commented Jan 24, 2012 at 19:06
  • show error, don't put value in operand stack..? ("0" is a wrong answer, and normal people don't know what "NAN" means.) Commented Jan 24, 2012 at 19:15

2 Answers 2

8

You're building a mobile calculator app not an actual calculator. Your output format is limited only by the number of pixels you allocate for the output area. Thus, why would you not provide helpful error messages for illegal operations? The default calculator in Windows 7 already does that:

divide by zero square root of -1

Since the basic layout doesn't support i the application returns the respective error message.

You can go a step further and make the error messages links to help info explaining the mathematical rules for such cases.

4
  • I was just formulating a similar response, so I'll be upvoting your answer. +1 for the screenshot :)
    – jcmeloni
    Commented Jan 24, 2012 at 18:35
  • @jcmeloni: To be honest, this questions is such a soft-ball that I didn't expect to be the first one to respond.
    – dnbrv
    Commented Jan 24, 2012 at 18:41
  • "Your output format is limited only by the number of pixels you allocate for the output area" - I would be inclined to disagree. My output format is limited by the type of the app, in this case defined as a simple/basic calculator. So I don't see how linking to mathematical rules would make sense. Providing error messages sounds like a reasonable suggestion, though.
    – user8597
    Commented Jan 24, 2012 at 19:11
  • @ErnestaOrlovaitė: Your output is presented on an high-res LCD as opposed to old-school LED displays, which could show only a limited number of characters. Once the app returns an error, the text (like Cannot divide by zero) can be made a clickable link to either internal help or some website.
    – dnbrv
    Commented Jan 24, 2012 at 19:19
0

I have owned real calculators that outputted something "-E-" if you try to perform an illegal operation (e.g. (-1)!).

Of course, modern real calculators have better error outputs and an app can output anything.

I have always thought that the (Reverse) Polish notation is not a good user experience.
- Why not enable a more natural input?

Even real calculators (e.g. Casio FX-991) are progressing to more and more natural inputs and outputs from (calculator) generation to generation.

Smart phones are supposed to be smart, not dumber than a calculator.

4
  • A smart smartphone calculator would allow you to switch between RPN and infix notation so that you have the option. Commented Jan 24, 2012 at 18:50
  • I don't think that anyone would choose to use the RPN or PN, therefore implementing it would be a waste of time and of phone storage (extra code = larger app). Even Microsoft has/had a "PowerToy Calculator" that enables natural input. Commented Jan 24, 2012 at 18:59
  • The option that allows switching cannot be defined as a "a simple calculator app for a smartphone". And it's not a question of whether anyone would use RPN. The issue is a more conceptual problem of how to deal with illegal user input when 1) the app is to be very simple, and 2) when the app closely resembles a real world item that has specific rules and experiences attached to it.
    – user8597
    Commented Jan 24, 2012 at 19:05
  • 1
    As I said, real calculator do have error messages and trying to imitate their constraints makes no sense. Commented Jan 24, 2012 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.