Wednesday, June 23, 2010

I Love This Code

Just saw the following at a client site...

if (name != null){
  person.setName(name);
}else if (name == null){
  person.setName(null);
}

I love it.  It could only be improved by being even more explicit.

if (name.equalsIgnoreCase("Allen")) {
  person.setName("Allen");
} else if (name.equalsIgnoreCase("Bob") {
  person.setName("Bob");
} else.
   /* omitting lines in this post */
} else if (name.equalsIgnoreCase("Zuzu") {  // hand cramp at line  1087667556223
  person.setName("Zuzu:);

} else if (name == null) {
  person.setName(null);
}


The only drawback I can see to this approach is that it is open to modification under new first names, otherwise, it is brilliantly self-documenting!  ;-)

No comments:

Post a Comment