Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: What operator should perl5porters use for safe dereferencing?

by perl-diddler (Hermit)
on Jun 25, 2012 at 01:16 UTC ( #978098=note: print w/ replies, xml ) Need Help??


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

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...)


Comment on Re^2: What operator should perl5porters use for safe dereferencing?
Re^3: What operator should perl5porters use for safe dereferencing?
by frozenwithjoy (Curate) on Jun 25, 2012 at 05:27 UTC
    Excellent argument! You can diddle my perl anytime perl-diddler!
Re^3: What operator should perl5porters use for safe dereferencing?
by Anonymous Monk on Jun 25, 2012 at 06:57 UTC
      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...

Re^3: What operator should perl5porters use for safe dereferencing?
by BrowserUk (Pope) on Jun 25, 2012 at 08:31 UTC
    "~" 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
        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?

        I do not believe so.

        In every accidental mis-usage scenario I can imagine, if the reference is undef, the result of the dereference expression will be undef, and so will trigger an undefined value warning the first time it is used.

        Of course, the first usage my be remote from its generation, but tracing undefs back to their source is a common enough procedure in Perl now, and is hardly rocket science. I do not see the shape of the operator being a major factor either way.

        I think the only way I can counter your premise, is to respond to example usage in-situ. And producing examples realistic enough to form the basis of serious discussion is very difficult.

        You inevitably end up arguing about the validity of the example, rather than the merits of the case being presented.

        In the end, I can only express my opinion along with everyone else's and counter what I see as bad arguments, in the hope of influencing those making the decision. Assuming it hasn't already been made.


        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?

      '-' 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.

        trying to compare mixes of the words with letter substitutions is fruitless.

        If you had read the post to which I was responding, you'd have realised that that is exactly the point I was making!

        Did you actually read all the way down to the third line of my post where I said:

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

        So before you jump to conclusions, read not just one post and then respond, but also the context in which that post was made.

        That is absurd.

        What I did -- emphasis the illogical through parody -- was eminently logical.

        What you did -- take a post out-of-context, and build an argument around your own misinterpretation of it -- was absurd.

        But don't feel too bad about it; you are not the first, nor will you be the last to do so.

        The only thing you should watch out for, is the temptation to compound your mistake, by trying to defend it.

        Good will!


        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?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2014-09-19 13:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (138 votes), past polls