I am used from writing in other functional languages, to use
where-statements for the internal details of a function. It makes for readable code, because a function will then end up reading like a ‘tree’: The most important high-level statement(s) are first, with explanations of the different parts of this high-level statement being explained in the following lines.
However, while Elm has support for
let statements, which allow you to specify details before writing a statement, the language does not support
I expect this was done for a reason, and I’d love to understand the reasoning behind supporting
let rather than
That decision would go back a long way. I think it was part of Elm’s deliberately minimalist approach not to have two things that are equivalent. I’m sure I saw a conversation about it on the old elm-dev mailing list somewhere, you might try searching it.
If you really wanted to you could use this odd style:
ret = x + y
x = 22
y = 333
I have unfortunately not been able to find it so far; probably because both let and where are such common words in normal english sentences. If anyone is able to find or remember this conversation, I’d be much obliged!
Indeed, this is what I expect as well, but (at least to me) it feels odd to pick
let rather than
where, because of the readability of hierarchically structured code.
Then again, of course this discussion, while being interesting, will definitely not have a change on what Elm supports today, since keeping features minimal is something to continue striving for (since adding something to a language is so much easier to removing something).
@Duncan Interesting idea, although I am a bit scared of being lynched by anyone who ends up reading my code .
The feature request discussion on github is pretty insightful, including some answers by Evan:
I think everyone’s seen that this has been proposed before, but just to provide an up-to-date summary:
where isn’t going to be implemented. The reasons are
- It’s redundant
let syntax is nice enough in our opinion
- If you want to change the order, you can make more top-level functions. Doing this will also make your functions shorter and easier to test.
I’m not sure there’s much else to discuss on this subject but I don’t know for sure so I won’t close this thread right now
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.