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 
<http://elm-lang.org/docs/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.

Reply via email to