5 ms·
I agree with your prof, and have a peeve with linters that complain about unnecessary parens. They may be unnecessary, but they can sure be helpful for those of
by hirundo 7y ago
I agree with your prof, and have a peeve with linters that complain about unnecessary parens. They may be unnecessary, but they can sure be helpful for those of us who don't have the precedence tables fully embedded in our neural code scanners.
- TeMPOraL 7y agoAlso they help if you're working in more than one language any given year, as there are differences in precedence rules between programming languages.
- williamdclt 7y agoIs there? I've never noticed precedence differences, and I would find that crazy!
- brlewis 7y agoScheme and Common Lisp have significant differences, but their precedence rules are identical.
- Izkata 7y agoEven when I have no issues with the precedence order, I often add parens anyway because it helps with mental grouping at a glance, instead of having to scan and mentally parse the line.
- cannam 7y agoA wise practice. As a young egotist I would often omit parens in complicated C expressions. I did this intentionally and in a very self-satisfied way - writing multi-line conditionals and lining them up neatly without parens with a metaphorical flourish of my pen. Then one day, chasing a hard-to-find bug, I realised it had happened because I'd mixed up the precedence of && and || in a long conditional. I was an idiot. Since then I've made a point of reminding myself that I know nothing and that there's nothing to be gained from pretending I do, and putting parens in everywhere. Sometimes, even now, I get those grandiose moments when I think the code I'm writing cannot possibly go wrong. Those are the moments that call for a bit of fresh air and an extra unit test or two.
- NotSammyHagar 7y agoThat's a great observation. Passing on that expertise is what wizened veterans can do to move our capabilities along and not let learning go to waste. I've heard that a big reason for sometimes struggling software engineering quality in countries and companies is places where the only way to grow is to become a manager - you need people to stay in technical paths so they can pass on that learned knowledge.
- nerpderp82 7y agohttps://news.ycombinator.com/item?id=3842713 https://news.ycombinator.com/item?id=3842713
- codebje 7y agoI heard an aphorism once I've tried to live by since: It is twice as hard to debug code as it is to write it. If you write code as clever as you can make it, you will never be able to debug it.
- samatman 7y agoIronically enough, given the article, this is attributed to Brian Kernighan.
- gweinberg 7y agoIf I were writing a linter I'd do the exact opposite: complain about a lack of parens if it might be confusing. I don't know if a / b * c is (a/b) * c or a / (b*c). Don't tell me, no matter how many times I'm told I'll forget 5 minutes later.
- AnIdiotOnTheNet 7y ago> If I were writing a linter I'd do the exact opposite: complain about a lack of parens if it might be confusing. Last I checked this behavior was still on the roadmap for Zig. It would be a compile error to not clarify such expressions with parenthesis.
- trickstra 7y agoExactly. Linters often complain about the amount of whitespace as if readability was important, but then complain about "too much" readability of the operator precedence. Except one can cause a programming error while the other can't.
- davedx 7y agoI have a peeve with linters in general. The useEffect dependencies lint rule for React is one the worst I’ve seen - “fixing” it changes the behaviour of your program. They are horribly opinionated and often leave you with less readable code. Bah
- earthboundkid 7y agoGofmt will add and remove spaces to imply order of operations.