Monday, September 26, 2011

what happens to the code without thought


I ran into this wonderful piece of java code at work. Just had to share this with everyone.
This code base was modified over last 4 years by at least 50 different developers with no TDD. Look at what the code ends up being in a long run.

// given that record and id are Strings
if (record != null && ((id != null && id.length() == 20) || (id == null || id.length() != 20))) {
  // do something
}

This if condition is essentially the same as

// given that record and id are Strings
if (record != null && true) {
  // do something
}

No comments:

Post a Comment