develooper Front page | perl.perl5.porters | Postings from March 2021

Re: Perl feature wish: quote-word array-ref operator

Thread Previous | Thread Next
From:
Paul "LeoNerd" Evans
Date:
March 13, 2021 13:16
Subject:
Re: Perl feature wish: quote-word array-ref operator
Message ID:
20210313131623.780d82b6@shy.leonerd.org.uk
On Wed, 10 Mar 2021 07:35:26 +0000
Smylers <Smylers@stripey.com> wrote:

> That's true, but is way harder to read: the gap between the [ and ]
> can be massive; not knowing what you're assigning until you get to
> the end of it doesn't make it easy to glance at the code.
> 
> Yes, there's precedence in // and s/// modifiers, but some of those
> can also cause ‘mental reparsing’ like that. (Note Perl 6 moved the
> modifiers to the front, like s:i//.) And generally those modifiers
> don't fundamentally change the type of what's being returned as much
> as this would.

Indeed; I have mentioned this before while discussing other features.
I'll requote from
https://www.nntp.perl.org/group/perl.perl5.porters/2021/01/msg258865.html

> It turns out that LR grammars are quite brutal on humans as well as
> computer parsers.

> One of the points of upfront try/catch notation is that it alerts the
> reader, when scanning down the code in the usual top-to-bottom
> fashion, that something fun is happening with respect to exception
> handling. Otherwise, you can be mislead as to the nature of the
> behaviour if you get a long piece of code that reads

>   {
>     ... # 50 lines of code here
>   } fail {
>     ...
>   }

> once you skip past those 50 lines and realise what was going on.

> In the sphere of natural languages there is the concept of a "garden
> path sentence"; to quote Wikipedia on the subject:

>   A garden-path sentence is a grammatically correct sentence that
>   starts in such a way that a reader's most likely interpretation will
>   be incorrect; the reader is lured into a parse that turns out to be
>   a dead end or yields a clearly unintended meaning. 
>     -- https://en.wikipedia.org/wiki/Garden-path_sentence

> "The horse raced past the barn fell." has always been my favourite of
> these. As perhaps you can tell by reading it aloud, it causes some
> mental upset when you have to reparse what it meant.

> I would consider it rude of a language to encourage programmers to
> write such programs, even if we can theoretically parse them.

Trailing modifiers on a qq()-like construction would be the same kind
of Garden Path Grammar.

-- 
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk      |  https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/  |  https://www.tindie.com/stores/leonerd/

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About