Thursday, October 20, 2005

What exactly does a software developer do?

When I tell people that I build software for a living, I assume they immediately get an image of what it is I do day after day. But other than sitting behind a computer for long hours, I don't think that anyone who hasn't developed software themselves really understands precisely what folks like me do.

Today I created some nifty little "methods" (aka functions) in the C#.net programming language I've been working with for the past 7 months. They simplify the process of correctly phrasing messages like this:

  • No files were copied
  • 1 file was copied
  • 2 files were copied

All are very similar in nature but subtilely different. And though some developers are willing to settle for "X file(s) were copied", I am not. So, in case you're interested, here is some simple but effective code to handle such phrasing:

public static string PrepareCorrectTense(int quantity, string noun, string verbSingular, string verbPlural, bool noFlag)
{
string phrase;
verbSingular = (verbSingular == null) ? "" : verbSingular;
verbPlural = (verbPlural == null) ? "" : verbPlural;
if (quantity == 0)
p
hrase = ((noFlag == true) ? "No" : "0") + " " + noun + "s " + verbPlural;
else if (quantity == 1)
phrase = "1 " + noun + " " + verbSingular;
else
phrase = quantity.ToString() + " " + noun + "s " + verbPlural;

return phrase.Trim();
}

public static string PrepareCorrectTense(int quantity, string noun, string verbSingular, string verbPlural)
{
return PrepareCorrectTense(quantity, noun, verbSingular, verbPlural, false);
}


public static string PrepareCorrectTense(int quantity, string noun)
{
return PrepareCorrectTense(quantity, noun, "", "", false);
}


And if you wanted to utilize these methods to handle the example shown above, you would do something like this:

PrepareCorrectTense(fileNum, "file", "was", "were", true) + " copied";

No comments: