Hacker News new | ask | show | jobs
by samuellb 3567 days ago
On the other hand, it's quite convenient to not have to do null checks in debug messages. Compare:

log.trace("doStuff(" + obj1 + ", " + obj2 + ")");

to this:

log.trace("doStuff(" + (obj1 != null ? obj1 : "null") + ", " + (obj2 != null ? obj2 : "null") + ")");

The second one is IMHO quite hard to read, even in this short example (and code readability is important when you do code reviews)

1 comments

That is why you should use string formatting instead of concatenation.

For string formatting, rendering "null" (or "") makes sense; for coercion not.

That just resolves into everyone always doing formatting, and never doing concatenation, which yields the same problem.