97 Things Every Programmer Should Know

(Chris Devlin) #1

(^132) 97 Things Every Programmer Should Know


Prevent Errors .................................


Prevent Errors .................................


Giles Colborne


ERROR MESSAGES are the most critical interactions between the user and the
rest of the system. They happen when communication between the user and
the system is near the breaking point.


It is easy to think of an error as being caused by a wrong input from the user.
But people make mistakes in predictable, systematic ways. So it is possible to
“debug” the communication between the user and the rest of the system just as
you would between other system components.


For instance, say you want the user to enter a date within an allowed range.
Rather than letting the user enter any date, it is better to offer a device such as
a list or calendar showing only the allowed dates. This eliminates any chance
of the user entering a date outside of the range.


Formatting errors are another common problem. For instance, if a user is pre-
sented with a Date text field and enters an unambiguous date such as “July
29, 2012,” it is unreasonable to reject it simply because it is not in a preferred
format (such as “DD/MM/YYYY”). It is worse still to reject “29 / 07 / 2012”
because it contains extra spaces—this kind of problem is particularly hard for
users to understand, as the date appears to be in the desired format.


This error occurs because it is easier to reject the date than parse the three or
four most common date formats. These kinds of petty errors lead to user frus-
tration, which in turn lead to additional errors as the user loses concentration.
Instead, respect users’ preference to enter information, not data.


Another way of avoiding formatting errors is to offer cues—for instance,
with a label within the field showing the desired format (“DD/MM/YYYY”).
Another cue might be to divide the field into three text boxes of two, two, and
four characters.

Free download pdf