Mat Trudel

@mattrudel

Ezra's Law

13 July 2008

Up on the plate today: the importance of thinking, problem reduction, and generalisation, as illustrated through tactical examples. Case in point: it really bugs me when people that oughta know better write stuff that looks like

if (a == true)
  if (b == true)
    return false
  else if (b == false)
    return true
  end
else if (a == false)
  if (b == true)
    return true
  else if (b == false)
    return false
  end
end

Up front, don’t laugh. I see crap like this all the time.

For those that may not see it, this is exactly equivalent to “a XOR b”, and so could be equally expressed as

return a ^ b

Or, if your language of choice doesn’t have XOR:

return a != b

I’m gonna go out on a limb and suggest that that code should never have been written. Any developer worth their salt should have seen that reduction right off the bat.

To paraphrase the always insightful Ezra Zygmuntowicz, “No code is better than no code”. I’m hereby christening this phrase as “Ezra’s Law”, and will publicly state that anyone I find not following it in our committed code will be flogged, or at least made to buy me a beer.

(Note: feel free to substitute [ ‘faster’ ‘more correct’ ‘more maintainable’ ‘clearer’ ] for ‘better’ )