But does this help? Now the simple nested query is some serious code.

I, too, like the idea that a query expression like the one shown should have a 
nice syntax… 
without the need for variables.

I always thought that the nice collection API would be nicer if we could write 
them without
parenthesis...

How to do that right is of course not easy.

There are experiments around, for example 

https://github.com/dvmason/Pharo-Functional


> On 26 Jan 2022, at 11:11, Sebastian Jordan Montano 
> <sebastian.jor...@inria.fr> wrote:
> 
> I agree that the expression is unreadable. What I would initially do is to 
> extract it into temporary variables.
> Like:
> 
> tree := json at: 'tree'.
> blobs := tree select: [ :each | (each at: 'type') = 'blob' ].
> paths := blobs collect: [ :each | Path from: (each at: 'path')]).
> ...
> 
> After you can see if you can extract the logic into different classes or 
> other methods.
> 
> Sebastian
> 
> De: "Richard Sargent" <richard.sarg...@gemtalksystems.com>
> À: "pharo-users" <pharo-users@lists.pharo.org>
> Envoyé: Mercredi 26 Janvier 2022 09:55:30
> Objet: [Pharo-users] Re: Too many parenthesis - a matter of syntax
> On Wed, Jan 26, 2022, 01:20 Kasper Osterbye <kasper.oster...@gmail.com 
> <mailto:kasper.oster...@gmail.com>> wrote:
> Cheers all
> 
> I have noticed that I often ends up with quite a number of nested 
> expressions, for example:
> 
> (((json at: 'tree') 
>         select: [ :e | (e at: 'type') = ‘blob' ]) 
>                 collect: [:e | Path from: (e at: 'path')])
>                         select: [ :p | p segments last 
>                                 in: [ :name | (name endsWith: '.md') | (name 
> endsWith: '.mic') ] ]
> 
> What kind of proposals (if any) have been for a different syntax which could 
> give a more streamlined syntax?
> 
> What's written is basically unreadable and syntax changes won't help.
> 
> Try taking out the constants and describing their relationship with a new 
> message or a couple of messages.
> 
> Without trying to understand it, it looks like you have some navigation 
> followed by some filtering / suffix selection.
> 
> Try to develop an expression that articulates the meaning of what you're 
> doing.
> 
> 
> My own thinking has been around an alternative to the cascade semicolon. What 
> symbol to use does not matter for me, but something like
> json at: ‘tree' º
>         select: [ :e | ((e at: 'type') = 'blob’)]º
>         collect: [:e | Path from: (e at: 'path’)]º
>         select: [ :p | p segments last 
>                 in: [ :name | (name endsWith: '.md') | (name endsWith: 
> '.mic') ] ]
> 
> Basically, a send the right hand expression to the result of the left hand 
> expression.
> 
> Has anyone ever tried this, or is it just one of the many small annoyances 
> best left alone?
> 
> Best,
> 
> Kasper
> 

Reply via email to