I'm aware of the reasoning. As you say, in C people would carelessly edit:
if (condition)
doSomething
to
if (condition)
doSomething
doSomething2
So fair enough, you protect against that. You cannot therefore conclude that:
if (condition) {
doSomething
}
is clearer or that 1 line if statements aren't clear. First of all, you've purchased your insurance at the cost of brevity. Which is quite a high price, especially when you have to use them constantly to write:
if err != nil {
return err
}
and when it forces all of your 1 line conditional expressions to be 4 - 6 lines, per my OP.
And there are solutions that allow you to buy your insurance without such a high price. You can invert the position of the if, as ruby does. You could make a rule that when you don't have braces you have to write your statement on the same line. The point is this isn't the only way out. And clarity is not the same as preventing one specific kind of error, which occurs only in a context which could be changed as well.
And there are solutions that allow you to buy your insurance without such a high price. You can invert the position of the if, as ruby does. You could make a rule that when you don't have braces you have to write your statement on the same line. The point is this isn't the only way out. And clarity is not the same as preventing one specific kind of error, which occurs only in a context which could be changed as well.