|Perl: the Markov chain saw|
Re: Operator Precedenceby tachyon (Chancellor)
|on Jul 22, 2001 at 16:45 UTC ( #98813=note: print w/replies, xml )||Need Help??|
In Perl there are many ways to do it. In production code the reality is that someone with less experience/knowledge/patience than you may one day have to maintain your code. Sure you can do it in one line. Sure you don't need brackets, or pod or comments or long var names..... to make your code run. We add all these things to make the code easier to debug, easier to understand, and easier to maintain. With parenths precedence is a gimmee, without it may not be. Perhaps one of the commenest problems I see on PM is why doesn't this work:
Sure all you need to do is add brackets or change the || to 'or' but this is not obvious. This aside I find code like this:
anoying as there is no precedence issue being addressed by the brackets - probably just a C hangover. There are however some problematic examples like:
Shorter is not always better. Never expect anyone to understand what you are trying to do as well as you do. Adding parenths takes a fraction of a second if you touch type. Sure don't go overboard but save your precedence expertise for GOLF. Personally I vividly recall precedence issues causing *interesting* bugs. I felt sure that I knew the precedence until I stepped through the code and realised Perl and I did not share the same views! This said brackets are not always good, consider these examples - the last fails.
In Section Meditations