by mathgladiator · 14y ago · 0 comments
> if (obj != null && obj.isValid()) { }
Which is semantically correct due to the fail-fast evaluate of AND, it does require a double check since it's strange from a logic point of view. This is one the reasons that brace languages are hard to optimize since you can't commute things that ought to commute.
If the two checks were independent (pure functions), it's not difficult for a compiler to determine that given enough program visibility.