Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: What operator should perl5porters use for safe dereferencing?

by BrowserUk (Patriarch)
on May 29, 2012 at 14:01 UTC ( [id://973029]=note: print w/replies, xml ) Need Help??


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

I voted for the first option because I think it is mnemonic, but some of the others are also

  • ~>: (hand)wavy deref.
  • ?> & ?->: questionable deref. (With a preference for the shorter.)

With ->? it looks like the test comes after the deref.

+> & !> just look like typos.

->-> looks like a double deref, rather than a single conditional one.

I find all those using & anti-mnemonic in that elsewhere it takes a reference, rather than dereferences one.

And those containing = look much too much like a fat comma. The parser may be able to distinguish them, but I don't think my brain would.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Replies are listed 'Best First'.
Re^2: What operator should perl5porters use for safe dereferencing?
by Anonymous Monk on May 29, 2012 at 14:29 UTC

    Interesting
     -> $rock->()->the->kasbah(); $rock->  ()->  the->   kasbah();
     ~> $rock~>()~>the~>kasbah(); $rock~>  ()~>  the~>   kasbah();
     &> $rock&>()&>the&>kasbah(); $rock&>  ()&>  the&>   kasbah();
     ?> $rock?>()?>the?>kasbah(); $rock?>  ()?>  the?>   kasbah();
     +> $rock+>()+>the+>kasbah(); $rock+>  ()+>  the+>   kasbah();
     !> $rock!>()!>the!>kasbah(); $rock!>  ()!>  the!>   kasbah();
     ->> $rock->>()->>the->>kasbah(); $rock->> ()->> the->>  kasbah();
     ->-> $rock->->()->->the->->kasbah(); $rock->->()->->the->-> kasbah();
     ==> $rock==>()==>the==>kasbah(); $rock==> ()==> the==>  kasbah();
     ?-> $rock?->()?->the?->kasbah(); $rock?-> ()?-> the?->  kasbah();
     ->? $rock->?()->?the->?kasbah(); $rock->? ()->? the->?  kasbah();
     &-> $rock&->()&->the&->kasbah(); $rock&-> ()&-> the&->  kasbah();
     &&-> $rock&&->()&&->the&&->kasbah(); $rock&&->()&&->the&&-> kasbah();
     -&> $rock-&>()-&>the-&>kasbah(); $rock-&> ()-&> the-&>  kasbah();
     -&&> $rock-&&>()-&&>the-&&>kasbah(); $rock-&&>()-&&>the-&&> kasbah();
     ->& $rock->&()->&the->&kasbah(); $rock->& ()->& the->&  kasbah();
     ->&& $rock->&&()->&&the->&&kasbah(); $rock->&&()->&&the->&& kasbah();
     -=> $rock-=>()-=>the-=>kasbah(); $rock-=> ()-=> the-=>  kasbah();
     =-> $rock=->()=->the=->kasbah(); $rock=-> ()=-> the=->  kasbah();
     ?> $rock?>()?>the?>kasbah(); $rock?>  ()?>  the?>   kasbah();
     ?-> $rock?->()?->the?->kasbah(); $rock?-> ()?-> the?->  kasbah();
     ?->: $rock?->:()?->:the?->:kasbah(); $rock?->:()?->:the?->: kasbah();
     ~>: $rock~>:()~>:the~>:kasbah(); $rock~>: ()~>: the~>:  kasbah();

      That seals it for me. ~> it is.

      Everything else just looks like an ant with the squits ran across the page even when you add a few spaces.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

        Heh. I had a similar reaction for ->> but I confess that ~> is a strong second.

        I'm curious, why add another operator? Why not use a prama to upgrade -> into being this new "safe" dereferencing operator?

        And then get it included in strict in perl 5.18 or 5.20. Once this new functionality is introduced, why would anyone still want to use the original dereferencing operator?

      Wow, amazing what a difference actual examples make!! Visually, ~> is the clear winner. Thanks for making the chart!!

      Elda Taluta; Sarks Sark; Ark Arks
      My deviantART gallery

      That eliminates ~> as far as I'm concerned. Way too similar to ->.

        The main problem I have with ~> is the change in shift key. The ~ is on the left side of the keyboard (at least my US-style keyboard), so touch typists will use the right shift key. > is on the right, thus the use of the left shift key. tchrist's "Twister" moniker comes in to play here - try typing it out a few times to see how easy/difficult it is. Maybe for hunt-and-peck typists there won't be much difference. For touch typists, we could come up with an alternative that was less discordant (such as ->>).

        The fact that a quick glance at code wouldn't always tell the difference between -> and ~> is, in my opinion, both a positive and a negative. Positive in that they are so tightly related and often that's good enough, but negative in having to mentally switch gears to actually pay attention and notice it when it matters.

Re^2: What operator should perl5porters use for safe dereferencing?
by Boldra (Deacon) on May 31, 2012 at 07:20 UTC
    If it's mnemonic, what does it remind you of?
    • =~ match
    • $~ $FORMAT_NAME
    • ~~ smart match
    For me, Tanktalus' argument about the typing is more convincing than a mnemonic argument.


    - Boldra
      If it's mnemonic, what does it remind you of?

      I did say: "(hand) wavey dereference".

      As for your examples $fred~>$bill looks nothing like $str =~ $re; or when $ref ~~ @things:.

      I'm not sure if that last example is valid syntax. I've never user smart matching in real code. I've tried it a few times when I thought it might work for me, but it either didn't do what I thought it would or gave a syntax error. I don't try any more.

      And as for $~, it not only looks completely different to ~>, I've never seen it used in code outside of its own documentation; and possibly obfu.

      A more poignant example might be something to do with boolean negation: ~$mask, but I tried and couldn't think of a single valid expression that looked vaguely similar.

      For me, Tanktalus' argument about the typing is more convincing ...

      "touch typists" who find things 'difficult to type' drive me nuts. The only people I've ever seen reach touch tying speeds when typing code, were copy typists.

      Programmers on the other hand, type a few symbols; pause; back up and change the variable name; pause; change it again; back up two lines and change the if to a while; then switch screens and look up an API; switch back and undo the last set of changes and start over...

      'sides, on my keyboard, it is left-shift '.', left-shift '#'. Easy :) Now if I could change the scalar sigil from $ to £, that would save me having to correct at least one Unrecognized character \xA3 in column 4 at... in just about every piece of new code I type.

      For me the strongest argument against it is that it looks so similar to ->. But actually, given its purpose, I even consider that a strength. Most of the time, the subtle difference will be completely transparent semantically and the subtle visual difference reflects that. Ie. It doesn't demand undue attention.

      And for those occasions when the difference is important; the code immediately following will have to reflect the fact that an undefined reference may exist.


      But in the end, someone, somewhere will make a decision based upon some reasoning, and it will satisify some and not others.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

        I've never user smart matching in real code. I've tried it a few times when I thought it might work for me, but it either didn't do what I thought it would or gave a syntax error. I don't try any more.
        Me too.
        Now if I could change the scalar sigil from $ to £, that would save me having to correct at least one Unrecognized character \xA3 in column 4 at... in just about every piece of new code I type.

        Acme::Currency to the rescue! :-)

      if we talk about mnemmonic rules...

      if you want to be safe "go to the hospital"

      +>

      But I must admit that is much less readable

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-23 21:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found