Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: What operator should perl5porters use for safe dereferencing?

by dsheroh (Parson)
on May 30, 2012 at 10:36 UTC ( #973250=note: print w/ replies, xml ) Need Help??


in reply to What operator should perl5porters use for safe dereferencing?

First gut reaction was ~> but, on further reflection, I decided that it's a bad match (no pun intended) for the normal meaning/behavior of ~ in Perl. =~ is a regex match and ~~ is a smart(ish) match, but this "safe dereference" isn't doing any kind of matching at all.

So I ended up voting for ->> because it's the same as the normal dereferencing operator, modulo a key bounce, making it quick to type. I think --> would have been more aesthetically pleasing than ->>, plus the added character is non-shifted which makes it a little more convenient to add/remove while debugging/testing, but it wasn't on the list of options.

My real preference, though, would be for -> to do a safe dereference by default, optionally with a warning. (Personally, I'd prefer any warning to only be enabled if explicitly requested, not just by a blanket use warnings or perl -w, but I recognize that this would be inconsistent with current warnings.) Given how often I find myself writing things like if ($foo->bar && $foo->bar->baz) {...}, I have to disagree with the earlier comment saying that if any link in that chain is undef, then you obviously have a problem - it's entirely possible that $foo may simply not have a bar and that's that.


Comment on Re: What operator should perl5porters use for safe dereferencing?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://973250]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (14)
As of 2014-08-27 14:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (238 votes), past polls