Should the programmer be aware of operator precedence thoroughly? Using braces to group expressions should be okay, isn’t? I always uses braces to be on safer side. And when asked a question on precedence, I cannot answer readily.
Should the programmer be aware of operator precedence thoroughly? Using braces to group expressions
Share
For very common operators – yes, it’s worth knowing it. If you put brackets round everything that would otherwise rely on operator precedence, your code would be unreadable (or easily confused with Lisp).
For more obscure operators – I’ve explicitly avoided learning them. If I start taking too many things for granted that I can’t reasonably expect other developers to know, I’ll start writing code which I can read easily but no-one else can. The best example is shift operators. I don’t even know (for sure – I have an inkling) which of these would be treated the same without the brackets, but I’m absolutely sure which is clearer:
or