Cost of correctness

I have a program that needs to print the results of a query. So I create a localizable string, use string.Format and print the results as in

Your query returned 5 results.

This looks good. Now a tester assigned to test this tried another query and got back

Your query returned 1 results.

And oops there goes a bug on my name. The question is how do I solve it. I have three options. Leave it as it is, make it result(s) or have two strings and switch between the two so that I get.

Your query returned 5 results.
Your query returned 1 result.

I am sure most users will immediately want me to use the 3rd option because it is the correct solution. The problem is that this has heavy localization, test and maintenance cost. Consider the following code that I need to use to get that done

if (resultCount == 1)
str = string.Format(singular, resultCount);
str = string.Format(plural, resultCount);

you can use tertiary operator for above but that complicates things further.

This piece of code needs testers to test both code paths, localization team to localize double the number of string in all supported languages. Some change in code need to be done at two places. Some costs are straight forward, outsourced localization is often charged per string localized :)

Even after that subtle errors creep in. For example the tester needs to ensure that in case of 0, 0 results is shown and not 0 result.

So the first two solutions appear to be better. However result(s) though popular choice before do not work any more. Screen-readers used by the visually-impaired fail on this. Modern style-guidelines favor 1 results over 1 result(s).

So next time you see a program show 1 results, don’t consider the programmer to be grammatically challenged :)

Comments (6)

  1. Marcelo says:

    My personal favorite is to reword this as "Result count: n".

  2. abhinaba says:

    Marcelo in some cases when you have to show info in one line this does not work. As in the output of a report we (Team Foundation Server) use.

    3 errors, 5 warnings.

    we do not have the real estate to use

    Error: 3

    Warning: 5

    Error: 3, Warning: 5

    sucks big time as comma ‘,’ does’nt stand out

  3. Gabe says:

    And don’t forget that this singular/plural distinction is specific to English (and similar languages). Other languages might have different localizations for 0, 1, 2, 3, 4, or other amounts. Of course this is all overkill for the languages that don’t have plurals.

  4. abhinaba says:

    Someone in our internal group pointed this out

    So incase we do have two strings (singular and plural) it’ll make the life harder for the person doing the localization.

    English  Slovenian

    0 files  0 datotek

    1 file   1, 101 …  datoteka

    n files  2, 102 … datoteki

    3, 4, 103, 104 … datoteke

    5, n datotek

  5. Kevin Daly says:

    On the other hand, the fact remains that "1 results" is simply grammatically wrong. It’s not a stylistic variant, or something people should be expected to allow for, it’s just incorrect.

    So my preference would be to rephrase the message to avoid having the number qualify the noun directly, even if that means abandoning the pretence of a full sentence (given that the machine doesn’t actually understand the language).

  6. Joku says:

    What about new flag to OS format function that will work like

    Format(1,ENUM_RESULT) == "result" (depending on UIlanguage)

    Format(2,ENUM_RESULT) == "results"

    Format(2,ENUM_MATCH) == "matches"


    This would reduce cost of testing and abstract the localization to OS. Since this kind of thing is quite common it seems surprising it is not in .NET BCL.