Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

by BrowserUk (Pope)
on Jun 25, 2012 at 08:31 UTC ( #978151=note: print w/ replies, xml ) Need Help??


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

"~" 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?


Comment on Re^3: What operator should perl5porters use for safe dereferencing?
Select or Download Code
Re^4: What operator should perl5porters use for safe dereferencing?
by phaylon (Curate) on Jun 25, 2012 at 17:40 UTC

    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?

        Oh, I didn't mean to counter all of your arguments with that point. It was more geared towards the visibility during scanning larger bodies of code. Especially that the general need to deal with the different behaviour would give a visual clue. This is what I would regard depending on that visual clue being there.

        With regard to undef hunting, I assume our typical day-to-day problems are just different. This is where I would really welcome a separate clue like a more distinguished operator. After all, undefined can also mean false, so a (remote) expression involving "~>" could very well result in valid, but unwanted behavior. At this point one might not even know that one is hunting undefined values.

        An additional scenario would be code reviews: I'd have to look much more closely to make sure nobody sneaks in a "~>" where it shouldn't be. This would even be for reviewing my own code. If I refactor a piece of code I have to pay more attention to the arrows.

        Just want to note that I don't regard your opinions as wrong, they just differ from mine. I hope I'm doing a half-way decent job at explaining why I hold these views :) Do you have anything against "?->" visually itself, or do you simply prefer "~>" for being more concise (or something else)?


        Ordinary morality is for ordinary people. -- Aleister Crowley
Re^4: What operator should perl5porters use for safe dereferencing?
by perl-diddler (Hermit) on Jun 28, 2012 at 20:58 UTC
    '-' 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?

        Forgive me if I was mistaken, but I thought you were responding to my having combined the whole operator of "->" with the whole operator "?"... I didn't break apart any operators that I saw. Were you not addressing me? Maybe that was my mistake.

        Sorry if you were addressing someone else...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2014-12-19 04:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (70 votes), past polls