What If It’s Null?
You find odd bits in any code base, especially one of significant age, with a few dozen different developers, that has gone through massive refactoring and redesign.
In fact, you might come across something like this:
...
TimeInterval timeout = this.parameters.getSecondsFromParameter("timeout");
if (timeout != null) {
setTimeout(timeout);
}
setTimeout(timeout);
}
Which might make you wonder how it works when the timeout is null, since it’s setting it either way. Diving into the setter yields:
public void setTimeout(TimeInterval timeout) {
if (timeout != null) {
this.timeout = timeout;
}
}
Ah, well that explains it. No bug, but some code smell.
Of course, even in newer applications you can find weirdness, like this odd python code from a recent project I worked on:
@staticmethod
def starts_with(value, prefix):
return value.starts_with(prefix)
Wait…wut?
Comments