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)?