in reply to Re: Operator Precedence
in thread Operator Precedence

The solution to *interesting* precedence bugs is not to throw in parenthesis for no reason. A prevention is always better than a cure. The examples you have given are a demonstration of my point. Why do you think the ternary operator has higher precedence than assignment?


$is_good ? $white : $black  += 1;

Yes, to someone who doesn't know the precedence table this is confusing. To someone that doesn't know any Perl I'm sure that the Howdy World program is confusing too. The solution is not to document every line in painful detail as to what exactly is going on so that people that don't know Perl can read your program.

The solution is that programmers learn the precedence table and soon what seemed like a cryptic and convoluted expression will magically transform into an obvious sequence of calculations.