Wednesday, June 13, 2007

Code quality

Computers are good at following instructions, but not at reading your mind
Dr. Knuth surmised this and the following snippet of a java code written by a professional programmer demonstrate this. What the programmer wanted was to find if the string value is empty. Look at the way computer is told to determine this:

// check for empty value
static boolean isEmpty(String value) {

Boolean isEmpty = new Boolean(false);
if ((value == null) || (value.length() == 0))
isEmpty = true;

return isEmpty.booleanValue();

}
Do you see, why I like to be in this profession and what I hate about it!
:-)

2 comments:

Prasanta said...

Such developers are actually not at fault... Their code reviewers are the ones who should be hanged. This guy/gal is perhaps just trying to justify the $$ (s)he is charging...

Anonymous said...

Who said verbiage is only for "traditional" languages