3 ms·
I think that if you don’t, you might end adopting superstitious “best practices” to compensate. For example: Countless engineers I’ve worked with don’t know op
by mailslot 7y ago
I think that if you don’t, you might end adopting superstitious “best practices” to compensate.
For example: Countless engineers I’ve worked with don’t know operator precedence. So tons of ”y = ((i * m) + b);” type stuff. Do not need any parentheses in this case, but if I remove them, then they have no idea what happens... So they litter all math with superstitious parens.
There are so many better examples, but you get the idea. I have suffered “coding standards“ that existed solely because of the devs that won’t RTFM.
- klipt 7y agoI'd think most people would remember * before + from school math, but for other operators the precedence is kind of arbitrary (can vary between languages) and adding parentheses to make it less ambiguous and more readable doesn't seem like the worst idea.
- mailslot 7y agoYes, it can vary, but it’s kind of important. If you don’t know the order of specific operators, or if your language violates math rules, a dev might want to know that instead of resigning to just not know things. For readability, yes... sometimes, but for readability sake, not “I don’t know what this does without them.” I’m not just talking about math operators, but logical ones too. I’ve seen people put parens around every “not” because they weren’t sure. There are three essential logical operators. Surely those can be learned at least. And yes... in those cases where readability is an issue, of if they’re necessary, please do add them, but please don’t if you’re unsure what “!a && b || c” does. Seeing “((!a) && b) || c” raises red flags.
- dmh2000 7y agoit would be interesting to know the frequency of bugs that are due to mistakes about operator precedence. even by experienced programmers. a lot? do use of parens reduce the frequency?
- UncleMeat 7y agoI think those parens can be good style. They communicate to people who don't know the binding, but perhaps more importantly they don't let you accidentally change order of operations if you change the operators in your computation.