The proper way to open()
david at cantrell.org.uk
Wed Feb 1 15:38:31 GMT 2012
On 01/02/2012 13:34, Smylers wrote:
>> On Mon, Jan 30, 2012 at 9:12 AM, David Cantrell
>> <david at cantrell.org.uk> wrote:
>>> No. The correct solution to buggy code caused by precedence is not
>>> to invent a new level of precedence, but to use parens.
> In particular, I don't look at a situation where OR behaviour is
> required and consider what precedence level is needed.
Nor do I. I use ||, and parens around (most) functions' arguments.
> To me the above open line doesn't look like a precedence issue, but
> using an operator in a way which doesn't fit.
Use of || in situations like this isn't unheard of in other languages.
C, for example.
> That the two operators
> happen to be different precedence variants of each other is an
> implementation detail, and that one can always be achieved with t'other
> doesn't seem a reason to avoid it any more than it would be to avoid ||
> because that Mr De Morgan showed it can be implemented with a
> combination of ! and &&.
Now you're being silly.
>>> I do realise that it was the p5p gang who invented the new level of
>>> precedence, but that doesn't mean you should play along.
> The sentiment of not blindly using a feature just because at some point
> it got added to core Perl sounds most sensible to me.
Still silly. I have never suggested that we should never use things
added to perl since some arbitrary point. I merely suggest not using
things that I think are stupid or pointless. Such as 'or' in perl 5,
and the yen sign operator in perl 6. On the other hand I quite like the
idea of 'state' variables.
While I agree that TIMTOWTDI is a Good Thing, many people don't seem to
understand what it means. It means that you can phrase a sentence in
different ways. It doesn't mean that there should be two different
words for "owl".
> And in general I find avoiding unnecessary parens is good, cos it means
> when I do have parens there are fewer of them, so it's easier to see at
> a glance how they match
Your editor can help with this. Hit % in vim or C-M-S-H-iaiacthulhu
while kicking an aardvark in emacs. There are no other editors.
Or more seriously, for complex expressions, no matter whether you use ||
or or or and or && a little bit of punctuation and indenting will make
it easier to read and less prone to bugs. Or you could split it into
David Cantrell | London Perl Mongers Deputy Chief Heretic
Deck of Cards: $1.29.
"101 Solitaire Variations" book: $6.59.
Cheap replacement for the one thing Windows is good at: priceless
-- Shane Lazarus
More information about the london.pm