A little while back, Caleb Tucker sent some fairly entertaining examples of a programmer not quite understanding the purpose of comments:
// Ask the user for the filename of the input file cout << "Please enter the input filename: "; cin >> filename;
// Variable to store the batting average float battingAverage;
// Return the batting average return battingAverage;
But, seeing that the author (who also happened to be Caleb) wrote the code for a freshman computer science class, I opted not to post it. But then just the other day, Darron Jennings sent in another example ... but this time, it's from real life code ...
At a recent code review my friend was asked to add comments to his code. This is not an unusual request, but this one got out of hand. After three iterations to try to satisfy his boss, he was told it still needed more comments. IN HIS DEFENSE, he thinks this is just as ridiculous as I do.
/// The FromXml method is used to take an Xml String and
/// deserialize it into the given type variable.
public static object FromXml(string input, Type type)
{
//Tracing statement
if (log.IsInfoEnabled) log.Info("Beginning Deserialization");//instantiate and initialize a generic object
object entity = null;//instantiate and initialize a string reader object
StringReader reader = null;//instantiate and initialize an XmlSerializer object
XmlSerializer serializer = new XmlSerializer(type);//Enter a try block
try
{
//Tracing statement
if (log.IsInfoEnabled) log.Info("Reading in XML");
//initialize the StringReader object with the provided input string
reader = new StringReader(input);
//Call the deserialization method of the XmlSerialization
//object using the loaded stringReader object as an
//argument and set it equal to the entity object.
entity = serializer.Deserialize(reader);
}
//Catch any excpeptions
catch (Exception ex)
{
//Tracing statement and error logging
if (log.IsErrorEnabled) log.Error(
"An Exception has occurred: " + ex);
//Throw the exception to the calling application.
throw new ArgumentException(string.Format(
"Error deserializing object input='{0}'",input));
}
//Finally block to test the reader, if it isn't already null close it.
finally
{
if (reader != null)
reader.Close();
}
//Return the deserialized object
return entity ;
}
If you've sent anything to me in the past few weeks using the contact form, please send it in again. There was a sever configuration problem blocking most emails coming from the form. Thanks.