News for hackers. Stuff that matters.
Re:How to use Elm at work by methehack on Monday July 11, 2016 @07:06PM (#12075492)
I wouldn't say it's understandable by all humans yet. I've had this experience where just when I think I'm grokking it, I hit a line of code that makes me cross-eyed and I can't find any traction at all and it's basically impossible to look up help. This is a combination of the maturity level of the project and also the documentation, but I get a distinctly not-quite-there-yet feeling with it (to be fair it is < 1.0). While elm has come a long way and has some great ideas, but I'm not 100% comfortable using it for something real yet.

I'm also not convinced by the cross-component communication / tree of components story yet. That still feels awkward to me. Not to turn this religious or anything, but tbh the static typing which feels like such a strength within a component, feels like it's in the way between components and results in some boilerplate, verbosity, and overly tight coupling. Really not trying to troll here -- I want to love it. YMMV.

Re:How to use Elm at work by oblique63 on Monday July 11, 2016 @09:50PM (#12076202)
> [static typing] feels like it's in the way between components and results in some boilerplate, verbosity, and overly tight coupling

Just curious, is this with regards to Elm / ML-style static typing specifically, or were you talking about it in combination with languages like C#/Java/etc?

I'm an elm noob, but I've been using F# for a good while, and its ML style of static typing is almost like the exact opposite experience of working with things like Java. Significantly less code, less boilerplate, and more expressive[0][1]. For example, one of the coolest features of F# that really showcase this, are type providers:

https://channel9.msdn.com/Blogs/Seth-Juarez/Type-Providers-i...

With them, you can leverage F#'s type system to automatically infer the structure and type of any external data source. Which means practically zero boilerplate or "ORMs" needed for things like reading-from/writing-to databases, making web api calls, parsing json/xml, or even interfacing with packages from entirely different languages like R [2].

So static typing can definitely have a lot of cool/practical benefits besides just catching bugs that make life easier, while still maintaining the flexible/lightweight feel of languages like python. However languages like C++ and Java have definitely seemed to have given it a bad name for a while, and haskell's whole tie-in with abstract math hasn't historically made it very accessible for us average programmers to notice all the tricks it has up its sleeve.

Elm is still young and I'm a total novice to it, but after working in F#, I'm definitely sold on it and like where it's going.

[0] https://fsharpforfunandprofit.com/series/why-use-fsharp.html

[1] https://skillsmatter.com/skillscasts/4971-domain-driven-desi...

[2] https://www.youtube.com/watch?v=_BOST3W88-Y

Re:How to use Elm at work by phamilton on Tuesday July 12, 2016 @12:38AM (#12076766)
So here's the Elm high level on the tree of components:

An Elm component is typocally a Model type and a Msg type. When side effects occur, the component receives a call to update with the model and the message. It returns a new model and a new side effect to cause (could be none). The model is then rendered into a view.

If you have a user profile component then maybe you have a user info component and a settings component. And maybe the settings component has a notifications component and a privacy component.

The Model for that is pretty straightforward. It's just a tree of data.

The Msg for that is what is being complained about. Any side effects caused by a child component will call the update function of the parent. It then has to route that to the child component.

The result is that you have:

type Msg = ProfileMsg Profile.Msg | SettingsMsg Settings.Msg

type Profile.Msg = ...

type Settings.Msg = NotificationsMsg Notifications.Msg | PrivacyMsg Privacy.Msg

type Notifications.Msg = ...

type Privacy.Msg = ...

So now your top level msg could be a SettingsMsg (Settings.PrivacyMsg (Privacy.SetDefault Privacy.Self))

And in order to process it in update you have to unwrap the outer type (like SettingsMsg) and then call update on the child component with the data from the msg. You repeat until a component can handle it. The the component returns a new model and possible new side effect. You wrap up that side effect in something like SettingsMsg and return it along with your new model.

It's a lot of boilerplate. As far as creating coupling, what if you want to use the notification component elsewhere in the app. Now something other than Settings needs to wrap it so you get Settings.NotificationMsg and Toolbar.NotificationMsg.

It just gets clumsy.

Re:How to use Elm at work by methehack on Wednesday July 13, 2016 @04:42PM (#12089525)
Thank you for taking the time to clarify and explain. That's exactly what I was talking about.

Worth noting -- it might be that there's just a missing construct/approach itty bitty piece of language support here that would make this problem a lot smoother.

I'm actually surprised I've not heard of anyone else express something other than complete satisfaction about it as it doesn't take much messing around to whack into it.

Re:How to use Elm at work by phamilton on Wednesday July 13, 2016 @08:23PM (#12090849)
It felt less verbose on 0.16 with the Mailbox forwarding.
Re:How to use Elm at work by wyager on Tuesday July 12, 2016 @12:38AM (#12076761)
> boilerplate, verbosity, and overly tight coupling

Can you give an example? Can't think of anything off the top of my head that fits this description.