Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Keep It Simple, Stupid
 
PerlMonks  

Re^4: use feature 'postderef'; # Postfix Dereference Syntax is coming in 5.20 (*)

by BrowserUk (Pope)
on Nov 26, 2013 at 16:12 UTC ( #1064429=note: print w/ replies, xml ) Need Help??


in reply to Re^3: use feature 'postderef'; # Postfix Dereference Syntax is coming in 5.20 (*)
in thread use feature 'postderef'; # Postfix Dereference Syntax is coming in 5.20

Ignoring the dubious nature of immediately flattening a returned array ref to an array, how is:

my @got = ExactlyWhatThisReturns( $exactly, $what, $it, $is, $based, $on, )->@*;

clearer than:

my @got = @{ ExactlyWhatThisReturns( $exactly, $what, $it, $is, $based, $on ) };
.

Or this mess:

my( $state, $zip ) = $user->GetAccount()->GetPriorOrder() ->GetShippingAddress()->@{ 'state', 'zip' };

Clearer than this:

my( $state, $zip ) = @{ $user->GetAccount()->GetPriorOrder()->GetShippingAddress() }{ 'state', 'zip' };

But I guess these things are in the eye of the beholder.


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.


Comment on Re^4: use feature 'postderef'; # Postfix Dereference Syntax is coming in 5.20 (*)
Select or Download Code
Re^5: use feature 'postderef'; # Postfix Dereference Syntax is coming in 5.20 (complexity)
by tye (Cardinal) on Nov 26, 2013 at 18:38 UTC
    my @got = @{ ExactlyWhatThisReturns( $exactly, $what, $it, $is, $based, $on ) };

    You've required an extra level of indentation. That adds complexity. In this case, with the made-up names, you compensated by removing an alternate level of indentation. But added complexity, even somewhat small, can add up. You can also squash that level of indentation with something like:

    my @got = @{ ExactlyWhatThisReturns( $exactly, $what, $it, $is, $based, $on, ) };

    but you've still added a layer of nesting. I believe a layer of nesting is fundamentally more complex than one more item on a chain of postfix operations.

    Also, in a case like:

    my @items = @{ $user->GetAccount()->GetPriorOrder()->GetItemCodes() };

    You have to mentally push a context that is moving in the opposite direction of the other operations. Again, a small cost in isolation, but just one more bit of complexity to add to the pile that might push something beyond a threshold for some readers and require a double take, and such disruptions in fluent reading of code can be jarring and significantly slow full comprehension.

    Reading the code your (well, my) mind goes, "Okay, I'm getting a list of items by dereferencing some... unknown thing, so we'll come back to that... Oh, I take the current user, get their account, get the prior order for that account, get the item codes for that order. Now, where was I? Oh yes, 4 operations ago I was supposed to remember a dereference. The '}' isn't followed by anything and um, oh yeah, we started with '@', so that means I'm turning a ref to an array into a simple list." Yeah, I find that way more complicated than what I'd have to think with ->@*.

    Alternately I can forgo scanning the code linearly and jump from the opening "@{" to try to find the matching "}" and then only push the simpler concept of "deref an array ref into a simple list". But I still have to mentally push the out-of-order operation. And visual jumping isn't free, especially if one of the functions involved takes complex arguments taking up half of a screen.

    I already mentioned one of my least favorite aspects of this:

    my( $state, $zip ) = @{ $user->GetAccount()->GetPriorOrder()->GetShippingAddress() }{ 'state', 'zip' };

    To understand just what kind of dereference is being requested, I have to line up two characters that are quite far apart in this code, the '@' near the end of the first line and the '{' near the beginning of the 3rd line.

    Also, consider that over the prior dozen years I've seen hundreds of people have significant difficulty when they've been doing $aoh->[$i]{$k} with no problem and then need to get something like the keys in one of the hashes and just draw a complete blank on how to do that. %{ $aoh->[$i] } is a significant departure in syntax.

    Heck, I had significant difficulty remembering the precise details of the various non-postfix (and less-often-used) ways of dereferencing until I realized that I could boil it down to references quick reference. I've linked to that node or seen others link to that node hundreds of times, almost always in reply to somebody having difficulty making the jump from postfix dereferencing to types of dereferencing that weren't possible via postfix syntax.

    Yeah, I've seen tons of evidence that it isn't just me who finds "SIGIL{ EXPR }SUBSCRIPTS" (where both the braces and the SUBSCRIPTS are optional) substantially more complex than postfix dereferencing.

    - tye        

      I should know better than to come back at you on this and just allow the visually obvious to win the day.

      (Especially as I don't really believe that you really believe half of what you've said in this thread.)

      But there are some things you said I just can't let pass.

      You've required an extra level of indentation. That adds complexity.

      No. It doesn't. Whitespace "adds complexity" is so obviously wrong. The "complexity" doesn't change one jot.

      The additional whitespace adds clarity. Better yet, it removes obfuscation.

      The reason we use indentation is to promote clarity; and improve readability. For the same reasons and goals (and achievements) as using paragraphs and sentences and bulleted lists in formal writing.

      Reading the code your (well, my) mind goes, "Okay, I'm getting a list of items by dereferencing some... unknown thing, so we'll come back to that... Oh, I take the current user, get their account, get the prior order for that account, get the item codes for that order. Now, where was I? Oh yes, 4 operations ago I was supposed to remember a dereference. The '}' isn't followed by anything and um, oh yeah, we started with '@', so that means I'm turning a ref to an array into a simple list." Yeah, I find that way more complicated than what I'd have to think with ->@*.

      I'd suggest that you're getting old, but i doubt your older than me, so that doesn't cut it.

      More likely, you are simple overstating the task. You are not a compiler. You do not need to process the entire statement to understand it.

      Its populating an array by dereferencing (a reference!) the return of a function call. (Full stop.)

      The function call returning that reference is .... (Full stop.)

      To understand just what kind of dereference is being requested, I have to line up two characters ...

      Again, no you don't. Again, you're overstating this.

      There's one bit -- made obvious by the "extra" level of indentation:

      $user->GetAccount()->GetPriorOrder()->GetShippingAddress()
      -- that chains through several method to finally arrive at what we want: a reference.

      Once we've got that reference, we dereference it and extract 2 fields from the hash. Clear as day.


      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.

        I should know better than to come back at you on this and just allow the visually obvious to win the day.

        (Especially as I don't really believe that you really believe half of what you've said in this thread.)

        Yes, your persistent presumption of bad faith on my part is indeed a problem (especially when the paranoia surfaces). But that is something you would have to choose to do something about.

        Whitespace "adds complexity" is so obviously wrong.

        An additional level of nesting does indeed add complexity. Using indentation to use whitespace to show this nesting indeed adds clarity. My complaint about the added level was not about the use of whitespace but about the adding of depth to the nesting.

        As for the rest, you seem to have a rather shallow perspective on the internal process of understanding code. I'm not surprised that the simple examples being discussed are such that you could perceive your understanding of them as instantaneous (and equally simple). Surely you sometimes come across code that you don't understand instantaneously. You might have to imagine such a case and then add one more layer of nesting to that construct.

        And I am not just making stuff up when I note that it is sometimes difficult to identify the '[' or '{' or lack of either that has to be combined with the matching prior '@' in order to understand which of three different types of dereferencing is being done. That you can't even imagine that being the case perhaps just means that you are ill suited for considering relative difficulty of parsing, since everything seems so trivial for you? I've also certainly seen other people be slowed by such complications.

        - tye        

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (16)
As of 2014-04-17 19:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (454 votes), past polls