Skip to main content

Posts

Showing posts from 2013

Being careful with nulls

Several times I've seen this "pattern":

if (object != null) { return object; } return null;
I just don't think it's very well thought out.

true, false... or *other*?

This was taken from real code :D The identifiers have been changed.

if (isCertainCondition()) { // Fine so far... } else if (!isCertainCondition()) { // Are you kidding me?? // ... // Now for the clincher... } else { // ... }

if not a and not b or not b and not a...

I just found this code that I thought was humorous (identifiers changed to protect intellectual property):

private boolean allFoosAreBarsOrBazs() { for (Foo foo: foos) { if (!(foo instanceof Bar)) { if (!(foo instanceof Baz)) { return false; } } if (!(foo instanceof Baz)) { if (!(foo instanceof Bar)) { return false; } } } return true; }