Hacker News new | ask | show | jobs
by rtfeldman 3505 days ago
Hi! I work at NoRedInk, the aforementioned company with 55,000 lines of Elm in production.

We don't "copy-paste the same stuff over and over." That would suck. Why would we be excited about a language that made us do that? Our Elm code is about as DRY as our JS code was before, except the Elm code is way easier to maintain.

1 comments

How do you compose update functions without writing the boilerplate let ... in for every Msg? How do you stop your main update function from growing endlessly as you add new Msgs?

You need only look in the standard library for examples of boilerplate and not-DRY code. The map function is implemented separately for Lists, Arrays, etc.

I really want to love Elm. But the more I wrote it the more I realised that the only answer to those questions is that you solve them with boilerplate and brute force. When I ask the community what the solution is I'm largely ignored or told it's not a "real" problem.

> How do you compose update functions

If there's shared logic between update functions we extract it into a helper function. That also makes it easier to test.

I'm not sure how typeclasses would make composing update functions easier, but in this case we can be concrete. PureScript's Pux library implements the Elm Architecture, and PureScript has typeclasses. Would you mind showing me some Pux code that uses typeclasses to improve the situation you're talking about?

Extracting to a helper function doesn't change the fact that there is boilerplate that must be overcome by brute force when composing "components". Every sub update function needs to be manually wired into the main update function since the introduction of Html.app. Libraries like elm-return make this a bit nicer to work with, but because of the restrictions in what Elm will let you do with it's "magic" there is no alternative.

I don't write PureScript, I can't help you there.

Don't understand how typeclasses would help you here. If you want immutable single source of truth, which is what Elm provides, you would do the same thing in Javascript/React and Clojurescript/Om.

I follow the same pattern in a 10k Javascript/React app I'm working on professionally. I don't see another way of doing things. Not that I'm looking very hard, cause this really isn't a problem.

It should be mentioned here that if map had the same implementation for both Array and List, map for arrays would probably be 10-20x slower than what it is today.

In that case, is it really boilerplate?

Yeah, that would be an example of where even if that langue feature existed, using it would lead to a worse implementation. :(