There are certain things in computer programming that some people do right, and some people do lazily. There have been times where I’ve taken the lazy option, but those are very rare, and when they do happen they don’t affect the user experience.
The worst kind of laziness is the kind that the person using the software can immediately notice, and nothing is more noticeable than bad grammar. A computer program doesn’t understand spoken language grammar, but the person writing the code should.
The classic example of this shoddiness is when an email program tells you:
You have 1 new messages.
It’s uncomfortable to read, and it’s completely un-necessary. Some programmers might take the next level of laziness as acceptable and show you:
You have 1 new message(s).
OK, it’s better, but it’s still up to the reader to decide if the s in brackets is needed to make the sentence work. It’s still incredibly lazy, because the code required to make it perfect is so trivial:
print(“You have “+msgs+”new message”+ (msgs == 1 ? “.” : “s.”));
So now, if the user has 1 message, there will be no s, otherwise message will be pluralized. A simple piece of extra code has given the end result the polish it deserves. You could even take this example a stage further by converting ‘1’ into ‘one’. The code for that isn’t so trivial but it would be a nice touch.
The example that made me write this post is a little different. I’m currently addicted to the Traveler IQ Facebook application, which reports in my news-feed when I improve my traveler IQ. The latest report says:
Mark now has a Oceania/Australasia Traveler IQ of 91.
Ignoring the fact that my southern hemisphere geography seems to suck, it’s a sloppy sentence. I can’t read it out loud, or even in my head, without cringing slightly, and it’s another trivial piece of code to make it right:
print(name+” now has a” + (substr(challenge,1,1) in (‘A’,’E’,’I’,’O’,’U’,’H’) ? “n ” : ” “) + challenge + ” of ” + score + “.”);
(Note I’m using pseudo-code in these examples, but most languages have similar constructs.)
So if you’re writing programs which output information to the user in plain English, please take a moment to consider if that plain English will be correct for all possible values of your variables. It doesn’t take long, and your end product will look more professional.