6 ms·
The operator precedence rules that are discussed here are a bit tricky and programmers could be excused to have to think a few secs before knowing how it was ag
by cjfd 7y ago
The operator precedence rules that are discussed here are a bit tricky and programmers could be excused to have to think a few secs before knowing how it was again. Therefore, it is better to use parentheses for these tricky cases. On the other hand, everybody should know without thinking that * has precedence over +, therefore, a * b + c * d should not have parentheses if it is intended to mean what is written. Parentheses would just be needless clutter in this case.
- kgwxd 7y agoI know * and + precedence without thinking about it, but when I see it without parentheses, I can't help but pause to be sure I'm not having a brain fart, and then also question why it wasn't just put in parentheses. So I just put in the parentheses or split up the steps, every time.
- mark-r 7y ago* has precedence over + because it's something we all learned as kids. Everything else is quite arbitrary and I wouldn't expect everyone to know it off the top of their head. I'm in the camp that believes there's nothing wrong with a few redundant parentheses.