CodeSOD: Plurals Dones Rights


Today, submitter Adam shows us how thoughtless language assumptions made by programmers are also hilarious language assumptions:

“So we’re querying a database for data matching *title* but then need to try again with plural/singular if we didn’t get anything. Removing the trailing S is bad, but what really caught my eye was how we make a word plural. Never mind any English rules or if the word is actually Greek, Chinese, or Klingon.”


if ((locs == NULL || locs->Length() == 0) && (title->EndsWith(@"s") || title->EndsWith(@"S")))
{
    title->RemoveCharAt(title->Length()-1);
    locs = data->GetLocationsForWord(title);
}
else if ((locs == NULL || locs->Length() == 0) && title->Length() > 0)
{
    WCHAR c = title->CharAt(title->Length()-1);
    if (c >= 'A' && c <= 'Z')
    {
        title->Append(@"S");
    }
    else
    {
        title->Append(@"s");
    }
    locs = data->GetLocationsForWord(title);
}

Untils nexts times: ευχαριστώs &s 再见s, Hochs!

[Advertisement] Manage IT infrastructure as code across all environments with

Puppet

. Puppet Enterprise now offers more control and insight, with role-based access control, activity logging and all-new Puppet Apps. Start your

free trial

today!

http://ift.tt/2tbWitJ

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: