Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: What operator should perl5porters use for safe dereferencing?

by Anonymous Monk
on Jun 22, 2012 at 11:51 UTC ( #977832=note: print w/ replies, xml ) Need Help??


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

I don't want there to be such an operator, because I want errors warned about as early as possible. I know the existing behaviour has many faults, but I still don't think the introduction of this operator is an improvement.


Comment on Re: What operator should perl5porters use for safe dereferencing?
Re^2: What operator should perl5porters use for safe dereferencing?
by perl-diddler (Hermit) on Jun 25, 2012 at 01:16 UTC
    I'm surprised at the number of lazy answer types on here "~>"? "~" is used in the context of binary NOT, or pattern matching. Neither has anything to do with conditional pointer referencing. you want to choose something, ideally, that makes sense in the language.

    Going from it being a conditional expression, the idea of a question mark naturally comes to mind as in a conditional statement like "x?a:b", here, you are questioning if the pointer is valid, if yes, do "->", implicitly, in the no case, the answer is "undef", so the ":undef part becomes superfluous. So "?->" seems clear to me.

    While it is in 2nd place, it's amazing how laziness outranks logic almost 3:1 -- (more general population would probably choose lazy over logical 10:1 I'd bet...)

      Excellent argument! You can diddle my perl anytime perl-diddler!
        It more likely has something to do with my background in compilers and having a degree in Computer Science.

        I'm much more likely to give an answer based on sound principles than on what's popular. Needless to say, that doesn't go over too well on a 'social' or popularity based websites...

      "~" is used in the context of binary NOT, or pattern matching. Neither has anything to do with conditional pointer referencing

      '-' is used in numeric subtraction; '>' is used in numeric greater than; both are used in numeric comparison <->.

      Neither has anything to do with pointer dereferencing -> .... D'oh!

      (You cannot break multi-character operators into bits to try and make sense of them!)

      ~> isn't just(*) the lazy option; it is also the logical option.

      The subtlety of the difference in the operators reflecting well the subtlety of the difference in the operation (note:singular) they perform.

      Ie. They both do the same thing -- dereference a pointer. The subtlety is that the new operator doesn't blow up if the variable it is applied to contains undef rather than a reference.

      Most of the time when scan reading the code; that subtlety will be unimportant. And when the difference becomes important, the code following the new operator will need to deal with its consequences and that will be more than sufficient to demarcate its use.

      *laziness -- the desire to not have to constantly type unnecessary boilerplate verbiage -- is a virtue in a programmer.

      It is why Perl programmers infinitely prefer to type:

      #! perl -slw use strict; print "What's your name? "; print 'Hello ' . <STDIN> . '!!!';

      Rather than

      import java.io.IOException; import java.io.InputStreamReader; public class HelloName { public static void main(String[] args) throws IOException { System.out.println("What's your name? "); // the BufferedReader is able to store some data for easier retrie +val BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(System.in)); String name = bufferedReader.readLine(); System.out.println("Hello " + name +"!!!"); } }

      I mean, honestly is it so good it needs to be said thrice? : BufferedReader bufferedReader = new BufferedReader(

      Even the damn comment is grievously wrong!


      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 disagree with regard to "logical." This is clearly a discussion about preferences. And for me "~>" is way too close to "->", and if the font makes it not look too similar, it also makes it not look like an arrow anymore.

        Your theory about skimming it seems to be dependent on the previous developer doing everything right. What if ~> was used by accident? What if it's in the wrong place of the expression?

        Thus, my personal preference is for "?->". I find it clearer, since it stands out more. This also has the advantage that somebody who doesn't know it doesn't just scan it as "->" and wonder why everything goes wonky. They see something that doesn't make sense to them immediately and have to look it up.


        Ordinary morality is for ordinary people. -- Aleister Crowley
        '-' is used in numeric subtraction; '>' is used in numeric greater than; both are used in numeric comparison <->.
        You are comparing apples & applets -- app isn't a root word so trying to compare mixes of the words with letter substitutions is fruitless.

        "->" is one token. "?" is one token.

        to disassemble -> into components doesn't make sense anymore than disassembling words into letters and having re-use of the letters mean something related.

        I'm practicing standard grammatical rules taking a "world" the ->", meaning something being pointed to, -- using it's standard meaning, and making a compound word by combining it with "?" -- a standard operator meaning only do the next thing if the left-operand is true, else do a false case. I'm not changing the meanings of any of the operators of subdividing operators, I combining whole operators and using their meanings as they are used in perl.

        ? evaluates the left operand, and, if it is true (i.e. !0 && ! undef), then do the action to the right, namely using the defined base, give me the offset @ "->offset".

        In the false case, it is a constant- "undef", so it doesn't need to be stated.

        You are trying to take the letters that compose words and mix and match them with other letters and expecting them to make sense on some level related to their original usage. That is absurd.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2014-11-24 03:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (135 votes), past polls