r/functionalprogramming • • Nov 20 '19

The Biggest Problem with Elm

https://medium.com/@cscalfani/the-biggest-problem-with-elm-4faecaa58b77
42 Upvotes

25 comments sorted by

6

u/zsombro Nov 20 '19

Interesting article! You should definitely x-post it to /r/elm

12

u/imright_anduknowit Nov 21 '19

I thought about it and decided not to. I think it would simply anger too many people. Definitely not my intent. This article is to help people to NOT make the same mistakes we did.

I'm afraid it would just fall on too many deaf ears to be worth it.

5

u/charkui Nov 21 '19

But how can you help the people if you don't share it with the folks that are actually working or learning elm? for that purpose it could help sharing it in those groups, you made an effort on the article so don't stop at halfway. it could help folks to avoid wasting their time or it could benefit the language, or even perhaps you learn something new.
Thanks for the article!

5

u/imright_anduknowit Nov 21 '19

Glad you liked the article. The climate of /r/elm isn't open to any criticism and so I'll get downvoted to oblivion. The Elm elite will come out and attack and those who have little or no experience will mostly make the choice to listen to the anointed. It's bad enough many people are respond to the article with I'm doing Elm wrong when none of them have any clue what our architecture is and most, if not all, have never built anything in Elm that's over 100,000+ LOC. So if you want to post it there, feel free. But don't say I didn't warn you :-)

2

u/Joshy54100 Nov 25 '19

Hey, I posted it there and that wasn't the experience in the comments at all. It seemed to be a mostly healthy discussion.

1

u/imright_anduknowit Nov 26 '19

I noticed and it was really nice to see. Thanks for posting.

5

u/alexkorban Nov 21 '19

I think it's a rather unfortunate article, because at least some of the problems could be avoided with a different design. 

It looks like the author used a JS-inspired component-like approach to organising code. This is often counter-productive in Elm. If you break up code into hundreds of tiny files, you won't have a good time either. There are at least two talks about this, and I wrote about it too: https://korban.net/posts/elm/2018-07-27-splitting-elm-code-into-multiple-files/. There are a couple of approaches to breaking up the update function, but essentially this is no different than breaking up any other long function; I see it as an advantage rather than a problem. Sure, you might need to call Cmd.map but it's hardly a catastrophe. 

A while ago I wrote a post about Task, which addresses the issue with making a sequence of requests: https://korban.net/posts/elm/2019-02-15-combining-http-requests-with-task-in-elm/. The approach could be extended to combine sequential and parallel requests if needed. Additionally, as suggested in the discussion of this post on the Elm Slack: "The parallel fetching could possibly be rewritten to always save the fetched requests, and then always call a function that uses Maybe.map4 to join them."

If you're evaluating Elm, I think the issues mentioned in passing in the introduction of the article are more important to consider than the rest of it.

2

u/imright_anduknowit Nov 21 '19

If TEA doesn't let you break things in to smaller modules, then for a 100,000+ LOC codebase, you're really not going to have a bad time. What other language proponents make such suggestions? I've never heard this in my 38 years of software development. I think I may have failed to really emphasize the biggest issue with TEA and that's constantly exiting your scope.

2

u/[deleted] Nov 21 '19

If TEA doesn't let you break things in to smaller modules,

Who ever said that? You can break your code up into smaller modules, but the way you were doing it isn't recommended. And usually you don't want super tiny modules because what you're doing is probably cosmetic and not actually helping with the architecture of the program.

2

u/imright_anduknowit Nov 22 '19

You are assuming the modules are tiny, most likely, based on your own personal experience. Get back to me when you've written 100,000+ LOC Elm program. Everything changes at scale.

1

u/alexkorban Nov 21 '19

Of course you can break things into modules (in fact, it's easy), I'm not sure who's suggesting otherwise. But I think the example you showed in the article where you have messages, model, view etc. for each in separate files is excessive, and probably created unnecessary overhead.

1

u/imright_anduknowit Nov 22 '19

You're comment is a common one I hear from people who have written very little Elm or have only written small programs in Elm. Try writing something at 100,000+ lines and then tell me about breaking up modules. Trust me, you're going to have to break things up to REDUCE overhead. It's crazy that the Elm community actually recommends massive monolithic modules. What other programming community on the planet does this?

2

u/amilner42 Nov 21 '19

Yes the design was questionable, but as I commented above, to me it just seems like a boilerplate problem. There's no denying Elm has a ton of boilerplate. I disagree about the "small hammer for a big job", it's just "one hammer that requires a specific design and a lot of boilerplate for all jobs"

2

u/alexkorban Nov 21 '19

Sure, Elm purposely values explicitness over brevity, and this is likely to rub you the wrong way if you'd rather write shorter code with more complicated abstractions.

2

u/amilner42 Nov 21 '19

Ya exactly.

1

u/pikodegayo Apr 17 '20

This package does some boilerplate essentially in that fashion

https://package.elm-lang.org/packages/0ui/elm-task-parallel/latest

11

u/LordOfSwines Nov 20 '19

Coming from Haskell I swiftly switched to PureScript after trying out elm for a new project. I still had an intern use Elm for a toy project however - I reckon it’s not bad for smaller projects if you are brand new to pure fp.

3

u/amilner42 Nov 21 '19

Super interesting article, I definitely find the overhead in Elm to be super high. It can be frustrating to write so many lines of code to do something simple because you always have to play within the rules (aka a nested update/msg/model because all state must be explicitly nested in the global model).

Is this a small hammer for a big problem though? I don't see how that fits into your argument. At least to me it just seems more related to boilerplate. The nested updates are boilerplate. Handling the async case you mentioned with the extra nested model....yet more boilerplate. Maybe I misunderstood your points, interesting article though.

2

u/r2tree Nov 21 '19

I suspect the premise of this post is wrong - to make parallel requests, you don't have to sequester the intermediate values into local variables. I'm not an Elm programmer, but these two posts seem to offer a better option using the `andThen` operator: https://spin.atomicobject.com/2016/10/11/elm-chain-http-requests/ and https://korban.net/posts/elm/2019-02-15-combining-http-requests-with-task-in-elm/

3

u/toastal Nov 21 '19

andThen is just bind. You use bind for sequential operations and apply for parallel operations. However almost nothing in Elm is built around parallel operations with andMap not being exposed or optimised. Things like applicative do make this a cake walk.

3

u/r2tree Nov 22 '19

The original article however uses an even more awkward approach than `bind`, and uses that to criticize the language. While Elm has many shortcomings, it is difficult to imagine that not being able to make multiple requests and merge their results as being the worst of them.

2

u/toastal Nov 24 '19

You're missing the breadth of this. It's difficult and often impossible to parallel operations which can be anything. It's a sign of a bigger problem. Considering I can just slap ado on something in PureScript and get an easy syntax for async ops, Elm doesn't have good legs to stand on.

0

u/thisiswarry Nov 20 '19

have you looked at Mint lang (https://www.mint-lang.com/) ?

2

u/imright_anduknowit Nov 21 '19

After a very quick look at the language, I feel like Mint is the Magpie of languages, collecting shiny objects from Javascript, Haskell, Elm, C++, JSX, etc. with no point of view.

It feels like a language AND a library AND a template language. I've never felt so confused looking at a language before.