Too each his own. Personally, I keep hearing about these bugs, but I can count maybe three times I've witnessed one first hand in two decades of coding. I have however frequently witnessed cases of five single-line ifs in a row stretched out into 30 lines of code. What could have been 5 lines of dense and vertically symmetric code was instead a sea of noise and whitespace.
if (test1) body1;
if (test2) body2;
if (test3) body3;
if (test4) body4;
if (test5) body2;
Between the two formats, I greatly prefer the second. It is understandable at a glance and makes the possible error in the last line stand out much more. In practice, I usually encounter the first style -even in cases as trivial as single-function-call-per-if.
if age>ageLowLimit then
givebeer
allowGambling
else: giveSoda
endif
Altough I use it when it improves readability (for instance, with short tests and instructions), I don't like that you seem to open the code block with the "then", but you don't close it.
6 comments
[ 2.8 ms ] story [ 27.3 ms ] threadBut yeah - "dense" is an adjective that I try to avoid when coding. Code should be clean, simple, and easy to read.
In Clojure:
or which is the same as: