[elm-discuss] Re: Is over-use of 'let... in' considered an anti-pattern?

2016-10-05 Thread Simone Vittori
I agree with everything said, however there's a specific case where I 
personally try to avoid `let` if possible.

Sometimes view functions can be quite big, hence it makes sense to split 
them into smaller composable functions.

So far so good, but as soon as we introduce the `let ... in` block, the 
diff will be worthless (as pointed in the style guide 
, producing clean diffs is one of the 
goals).

So in these cases I think it's best to add new functions at the bottom 
instead. 

As an example, instead of:

view model =
let
viewFoo =
...

viewBar =
...

viewBaz =
...
in
div []
[ viewFoo
, viewBar
, viewBaz
]




I'd rather go for:

view model =
div []
[ viewFoo model
, viewBar model
, viewBaz model
]

viewFoo model =
...

viewBar model =
...

viewBaz model =
...


However this is just my opinion and I don't feel like I have to strictly 
follow this convention. It may depend from case to case and having a dirty 
diff doesn't really matter in the end.


On Tuesday, 4 October 2016 21:04:31 UTC+1, Andrew Radford wrote:
>
> I've been trying out Elm, and although I have a little functional 
> programming experience from F#, mostly I have used OO languages. With my 
> experiments in Elm, I have found sometimes I end up with something like this
>
> foofunction model = 
>   let 
> something = foo bar baz
> somethingElse = foo bar baz
> yetMoreStuff = foo qux thud
>   in
>{ model 
>   | fieldA = something
>   , fieldB = somethingElse
>   , fieldC = yetMoreStuff
> }
>
>
> ... anyway I hope you get the idea. A style of function which lot of lines 
> in the 'let' block before generally one final thing in the 'in' block. In 
> F#, this sort of thing didn't look so bad as the stuff in the let block 
> would be all applied with individual 'let' functions. However in Elm they 
> start to *resemble *OO/imperitive style variable assignments, which makes 
> me question whether this is the Right Thing to do, or would it be 
> considered stylistically better to do something else, like for eg chain the 
> model through individual updating functions using '|>'.  Any strong 
> opinions about this? Have not seen too much about it in the style guides 
> etc that I have encountered
>
> Andrew
>  
>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Is over-use of 'let... in' considered an anti-pattern?

2016-10-05 Thread 'Andrew Radford' via Elm Discuss


On Wednesday, 5 October 2016 01:55:40 UTC+1, Max Goldstein wrote:
>
>
>> they start to *resemble *OO/imperitive style variable assignments
>>
>
> But they're not. You can't assign to the same value more than once. You 
> can actually have some values before the *in* depend on others, but you 
> can't do so circularly-- so subject to those dependencies the values may be 
> bound in any order. And doing these assignments can only affect anything 
> else through how the in-expression is used; they don't attach to an object 
> or contaminate global scope. 
>
> Chaining is great when you want to apply many transformations in sequence. 
> Let-bindings are parallel. If it makes sense to have reusable, atomic 
> update functions for your record ("updateVelocity"), go for it. But doing a 
> batch update of a record with let-bound values feels more natural.
>

I guess that's the crux of it - I do understand they are not variable 
assignments, but with a lot of them, they start to give that appearance, 
especially if conceptually unrelated values are being applied to different 
fields. So I suppose a better style would be to have only related things 
inside the let, i.e only be wary of a large 'let' block if there are a 
number of unrelated things in there, but if there is a large number of 
related things (a 'batch' as you say) then that's totally fine.


 

>  
>
>> Any strong opinions about this?
>>
>
> We try not to have strong opinions. Write code that is correct, explicit, 
> and concise (prioritize in that order). Language features and code style 
> are in service to that goal. 
>

A noble sentiment and one that I agree with. However, I don't know what it 
is about software, but having worked in the industry for years now, I've 
probably come across more strong opinions than you've had hot dinners ;)
 

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Is over-use of 'let... in' considered an anti-pattern?

2016-10-04 Thread Max Goldstein

>
> ... anyway I hope you get the idea.
>

If the real code was this short, I'd suggest inlining it, but the real code 
is probably long enough to warrant this style.
 

> they start to *resemble *OO/imperitive style variable assignments
>

But they're not. You can't assign to the same value more than once. You can 
actually have some values before the *in* depend on others, but you can't 
do so circularly-- so subject to those dependencies the values may be bound 
in any order. And doing these assignments can only affect anything else 
through how the in-expression is used; they don't attach to an object or 
contaminate global scope. 
 

>  eg chain the model through individual updating functions using '|>'
>

Chaining is great when you want to apply many transformations in sequence. 
Let-bindings are parallel. If it makes sense to have reusable, atomic 
update functions for your record ("updateVelocity"), go for it. But doing a 
batch update of a record with let-bound values feels more natural.
 

> Any strong opinions about this?
>

We try not to have strong opinions. Write code that is correct, explicit, 
and concise (prioritize in that order). Language features and code style 
are in service to that goal. 

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Re: Is over-use of 'let... in' considered an anti-pattern?

2016-10-04 Thread Joey Eremondi
I'd actually say the opposite, underuse of let is an anti-pattern, and
functional programmers are particularly guilty of writing one long
unreadable expression. Let breaks things up nicely, and each variable name
serves as a nice "comment" describing what the intermediate expression does.

On Tue, Oct 4, 2016 at 1:42 PM, Richard Feldman  wrote:

> I think this is totally fine. Nothing to worry about. :)
>
> --
> You received this message because you are subscribed to the Google Groups
> "Elm Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to elm-discuss+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Is over-use of 'let... in' considered an anti-pattern?

2016-10-04 Thread Richard Feldman
I think this is totally fine. Nothing to worry about. :)

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.