in reply to Re^4: use feature 'postderef'; # Postfix Dereference Syntax is coming in 5.20 (*)
in thread use feature 'postderef'; # Postfix Dereference Syntax is coming in 5.20
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: use feature 'postderef'; # Postfix Dereference Syntax is coming in 5.20 (complexity)
by BrowserUk (Patriarch) on Nov 26, 2013 at 19:42 UTC | |
by tye (Sage) on Nov 26, 2013 at 20:59 UTC | |
by Your Mother (Archbishop) on Nov 26, 2013 at 21:17 UTC | |
by tye (Sage) on Nov 26, 2013 at 23:39 UTC | |
by BrowserUk (Patriarch) on Nov 26, 2013 at 21:46 UTC | |
by BrowserUk (Patriarch) on Nov 27, 2013 at 01:34 UTC |