order of operations is a useless source of confusion -- we should just use parens always and avoid ambiguity. #toomuchcprogramminglately
You could argue from consistency that the standard convention is more aesthetically appealing, though. I tried writing this in a HN post but it boiled my brain so I sketched it on the back of an envelope instead.
http://images2.bingocardcreator.com/blog-images/hn/arithmeti...
Basically, assume high school algebra works the way you think it works. If we treat unary negation like it magically grabs the nearest integer prior to the exponent happening, things we assume are equal in high school algebra start to break catastrophically. You'd have to invent a new and perhaps uglier way to do algebra which would lose properties like "moving terms around the same side of an equation on paper for clarity is allowed because it doesn't change what they sum to."
Anyhow, if this ever comes up in my household, I'm going with "Yeah, that one's weird. Your dad didn't like it either, but convention is that -2^2 is -4. That's totally separate from math, it's just how we choose to represent math in squiggles, and this collection of squiggles is supposed to be read as -1 * (2^2) instead of (-1 * 2)^2 . Why did we pick that math-to-squiggles mapping? Long story and kind of boring, but it's sort of important that everyone read the squiggles the same way, for the same reason that we don't get into an argument over which side of a road should be called 'left' and then smash our cars into each other. Either way would have been a perfectly good 'left' because left is ultimately just squiggles, but now we're stuck with one of the squiggles."
In my ideal world, -EXPR would be a parse error, and it would only be valid to write -LITERAL * expr. (-1 * a.) So, you could have -4^2 is 16 because the - would not associate to the nearest constant, but rather be part of the 4-value.
The reason for this is that -a^2 is super confusing, and I believe it should be treated as invalid. I do not think that promoting the order of precedence of unary - is the best solution because it leads to the common confusion of thinking "well, a is already negative, so there is nothing to do". if instead this was explicitly -1 * a ^ 2, then you can always "plug and chug" with simpler rules.
Essentially, the confusion is because unary negation is the only operation that is confuse-able with the value definition.
Final qualm against unary negation: what does --4 evaluate to in ruby? 3? No. 4.
If I had my way, then --4 would clearly be invalid because the inner -4 could not receive the unary negation.
In more programming stuff, I think that mixed-type operations should be illegal (no implicit casts!) adding an int64 to an int32 and storing the result in an int32 should be a compiler error!
1 - 4^2
The answer is -15.
So what is
0 - 4^2
Most will say -16.
To be consistent we must agree that -4^2 is -16 since it is the same thing as 0 - 4^2.
It takes a while for students to understand this. I still get calculus students who mess it up.