Register / Log in

It seems like a while ago, my voicemail always used to tell me “You have 1 new messages, and 4 old messages.”  Thanks Voicemail.   You sound so intelligent when you say “1 messages”.

I was thinking that this kind of thing was going away.  Until today.  I was just using Google Reader and saw this message:

“You are following 1 people. You can hide, edit or pick your sharing groups in sharing settings.”

I’m really surprised to see this coming from a company with the clout of Google.

OK, while this isn’t that big of a deal (after all, I still understand what is being said) this is such an easy thing to fix in code.  So easy, that something like this should never come up in a real application!

Many programming languages have the ternary operator (condition ? if_true : if_false) that can solve this problem with a single line.  This operator works like this in Java (I believe this is identical usage to C++ and C#):

boolean cakeIsGood = true;
System.out.println(cakeIsGood ? "I love cake!" : "I don't like cake.  Only vegetables.");

Using this kind of a statement, it is extremely easy to deal with the problem of printing “1 messages”, as shown below.

int count = 1;
System.out.println("You have " + count + " new message" + (count == 1 ? "" : "s") + ".");

I know this gets a bit more complicated when you are dealing with language translations, because not every language handles plural nouns in the same way.  However, failing to make your application grammatically correct destroys the credibility of your program.  Take the time to ensure that text in your program is correct!

View Comments

blog comments powered by Disqus