I am the author of Elm in Action. Ask Me Anything!
Richard Feldman
・1 min read
I am Richard Feldman, author of Elm in Action and instructor of the Frontend Masters Elm Workshop. The main open-source projects I'm working on right now are
elm-test and
elm-css.
I work at NoRedInk, where we have 80,000 lines of Elm code in production. We introduced Elm in 2015, and since then our production Elm code has thrown a total of zero runtime exceptions. We hired Elm creator Evan Czaplicki in 2015 to continue developing the language, and we're hiring!
I'll be here until noon Pacific Time. Ask Me Anything!
The new MacBook Pros are overpriced
I've been a Mac user for over a decade but I'm lacking enthusiasm towards the r...
Are there any chances Elm development will become more open? It's easier to get info about future Apple products than to guess what's happening to the Elm language next.
How's Elm Software Foundation doing now? It was publicly announced about a year ago. But it's still not very clear what the purposes are, who's on board and what's the roadmap.
Thank you!
I think Elm doesn't have a concrete roadmap because Evan adapts his plans based on what he learns from the community. If you ask him "what will you be working on 6 months from now?" the answer will probably be "depends on what happens in the next 6 months." He does post periodic status updates on the elm-dev mailing list, if you're wondering what he's working on and how it's going.
My understanding is that the Elm Software Foundation is primarily for organizing money-related things. The main reason it exists is that Evan is friends with Python creator Guido van Rossum, and Guido recommended that he set up a nonprofit a la Python Software Foundation. It's not really for project management or anything like that.
That's great, but how can we get Evan interested in community feedback that have already been crystalized in "meta" issues on github for the virtual-dom, html, elm-compiler? Like this one github.com/elm-lang/html/issues/53
Actually, there is a status report on elm-dev now. Same day as I've asked this question :)
It was almost two months since the previous one.
how can we get Evan interested in community feedback that have already been crystalized in "meta" issues on github for the virtual-dom, html, elm-compiler?
Another way to phrase this is "how can we get Evan to stop working on what he thinks is the most important thing, and instead to work on what we think is the most important thing?"
Ideally everything would get addressed sooner rather than later, but there isn't time for everything, it's impossible to please everyone, and prioritization is hard.
For example, right now there are a lot of people who literally cannot use Elm because it doesn't have sufficient asset management tools to get acceptable performance on low-end mobile devices.
I don't think Evan is wrong to focus on that right now. :)
Another way to phrase this is "how can we get Evan to stop working on what he thinks is the most important thing, and instead to work on what we think is the most important thing?"
No, actually another way to phrase this is "how can we get Evan to start doing frontend stuff in Elm every day".
Your answer on another question about Evan's involvement in NRI day-to-day tasks is practically 0 is the saddest thing I've learned today. I might be wrong, but this is harmful to prioritization.
I think you're underestimating the amount of feedback he gets from all different corners of the community as to what the most important thing is. There are so many people with different priorities who think their particular thing is the most important.
If Evan worked directly on our production code base, he'd probably feel pushed to bump priority for the things that matter most to us, at the expense of all the other voices he hears. As members of this community, that would be a very short-sighted preference for us to have.
Languages tend to be designed one of two ways: By committee or by BDFL (benevolent dictator for life). Elm is clearly the latter, and it’s hard to argue against that considering how well Elm has turned out under Evan’s watchful eye.
One unfortunate consequence of this is that there’s quite a few native browser functions that don’t have Elm-equivalent APIs, or there are Elm equivalents that feel incomplete (shameless plug).
There’s this conundrum as an Elm user who’s come to appreciate Evan’s design sensibilities. I find myself frustrated over the tight control of elm-package (in particular, restricting native modules from the community), or long-standing issues without even a comment. On the other hand, I understand why it’s this way; It just doesn’t prevent it from being a source of frustration.
Evan is only one person, and this is beginning to become a popular language with diverse needs. Are there any plans to address this?
I totally get the frustration, but basically I think this is the least bad option. We've tried various ways to accelerate this, and all the cures have ended up being worse than the symptoms.
That said, Evan moves much faster than TC39, so catching up seems more or less inevitable—just not as quickly as we'd all like. :)
Can you explain the structure of the main NoRedInk Elm app? With it being the largest Elm app in the world it, would be really cool to know how it was structured and what you've learned along the way scaling up?
Sure! I should emphasize that we don't put a big priority on "getting this right." More than anything we try to be consistent (but don't always succeed), and the compiler makes it pretty easy to rename things if we change our minds, so we don't sweat it. (The biggest drawback to renaming is plain old vanilla merge conflicts.) So I wouldn't take any of this as advice so much as a data point if you're curious. :)
We have a series of pages, e.g. "Teacher Dashboard", "Grading", "Splash Page". Each of these has its own
main; back when I joined the company we were a non-SPA Rails app, and we have not transitioned to SPA yet. (We have long-term plans to head in that direction, and I don't expect the transition to affect our module structure much - outside of
main, of course, but
mainmodules are a small fraction of our total modules.)
We have a top-level module namespace called
Nrifor things specific to our UI, as opposed to things that we might open-source someday (e.g. the
Analyticsmodule, the
Emojimodule, etc). Here's an example of three related ones:
Nri.QuizHeader.Model
Nri.QuizHeader.Styles
Nri.QuizHeader.View
So our Quiz Header has a model, and a view, and some
elm-cssstyles. (We've been migrating from Sass to elm-css and it's been sweet!) We don't have a
Nri.QuizHeader.Updatebecause the quiz header doesn't have any state. I think this is worth emphasizing, because I see people create a model/update/view any time they want to reuse code, and I think that's the wrong way to scale. Unnecessary state management is bloat! We had no need for an
updatefunction here, so it was simpler not to have one.
Plenty of times we just have a module to hold
view, and plenty of others it's not even a separate module, it's just a plain old function inside an existing module, e.g.
viewSidebar : User -> Html msg
We also have reusable views that are used across multiple pages, for example:
Nri.Tabs
Nri.TextInput
Nri.Toggleable
Nri.Tooltip
All of these are stateful, and their APIs looks like github.com/evancz/elm-sortable-table - they do not define their own
Msgtypes, and callers don't have to use
Cmd.map. Their states are super simple, and defining their own
Msgtypes would have been overkill - more trouble than it was worth. This is also worth emphasizing; immediately reaching for a custom
Msgand
Cmd.mapany time local state is involved is a surefire way to get needlessly overcomplicated wiring.
My rule of thumb is that reusable views where
viewreturns
Html msginstead of
Html Msgare nicer by default, and I only reach for a custom
Msgonce I have enough state transitions that
Cmd.mapwould reduce verbosity substantially.
Finally we have some reusable data structures, which begin with
Data., for example:
Data.Assignment
Data.Assignment.Decoder
We debated the right namespace for these and settled on
Databecause what they have in common is that they're about representing and encoding/decoding some piece of data.
These are a mix of various union types and type aliases that represent common data structures in our app. Some of them have a lot going on, so it's decently common to have a data structure defined in one module, and then the decoder and/or encoder in a separate module. It's no big deal if they live in the same module, though. Again, we don't spend a ton of time on module structure because it's so easy to change reliably if we change our minds.
Hope that helps!
Very helpful, thanks
Where do you draw the line of functionality in your 'let/in' before breaking out into multiple functions to accomplish the same thing?
I find myself commonly having 5 or more variables defined in my 'let' that are staged versions of the first and wonder if that is a bad thing.
I tend to pull things into the toplevel early and often, but I also tend to use the
(|>)operator wherever possible.
That said, I wouldn't call having several declarations in the same
leta bad thing per se. So long as you find it readable, it's unlikely to cause problems outside that
let, so I wouldn't worry about it. :)
Richard,
I use some jQuery plugins, d3, and react in my application. We use a ton of Elm too!
We are having trouble embedding components in our Elm applications. Working with ports is a great abstraction to help us protect the purity of our lovely Elm world. However, many of the projects I embed in my Elm project hook up event listeners to DOM elements. This causes memory leaks because there's no way for the component to know it's being unloaded.
You seem to have some experience with this at NoRedInk - the jQuery Datepicker plugin by XD Soft.
Do you know if there's any intent on providing a mechanism for the modules we embed in our Elm app and interact with through ports to be notified when the DOM is being recreated or going away?
This is our last major hurdle for converting ALL of our frontend code to Elm. If we try to embed our D3 graphics in Elm it would cause MAJOR performance issues. I understand I could write this in Elm but it works great and would be costly to reimplement.
We haven't run into performance problems around this, but thank you for surfacing it! There was some discussion around whether this was needed, and the consensus was "in theory it would be useful, but in practice, who knows if it's actually necessary?"
Seems like you've found a case where it is! I'd post specifics of your use case on github.com/elm-lang/virtual-dom/is... - ideally with a link to the D3 code in question.
The blog post for Elm 0.17 mentions: "Generated JS is smaller and works with Google's Closure Compiler"
Do you have any experience/numbers on this? Do you know if Google's Closure Compiler is superior for making Elm's JS small (compared to UglifyJS, for example)?
At NRI, this isn't really a concern or issue. We don't use Closure compiler, and we currently don't need to. There's a bunch of posts on the mailing list about this though -> groups.google.com/forum/#!searchin... and groups.google.com/forum/#!searchin...
Yeah, I don't have any personal experience comparing them. Sorry!
When you first began using Elm at NoRedInk which parts of the system did you begin to port across first? What were the road blocks you encountered to begin with and any advice for other teams who are thinking of slowly moving away from React like environment to Elm?
We actually started with some business logic in our quiz engine. I wrote a guide for how to do this, but I haven't updated it since Elm 0.16. (This reminds me that I should really get around to that...) I forget where we first used Elm for actual rendering, but it started to snowball pretty quickly after that.
The biggest roadblocks were around build tooling. I didn't do a good job figuring out how production deployments (via Rails - we hadn't started using Webpack at that point) would differ from development builds, and the build tool plugin ecosystem wasn't as far along as it is today. (And it's still got a ways to go.) I guess maybe "roadblock" is too harsh, since we got past it, but even after migrating a bunch of stuff to Webpack we're still dissatisfied with our build process overall—and not just with the Elm parts.
Can you describe your experience with Elixir/Erlang/OTP so far? Do you have a rough estimate of the ratio of Ruby to Elixir being used for the backend @ NoRedInk? Do you see the company moving more and more of the backend to Elixir in the future?
Thanks,
-Josh
Elixir is super new for us, so the back-end is still almost exclusively Ruby.
We have one Elixir service in production right now, and it's not user-facing. We are currently working on our first (small) user-facing Elixir service, and once that's done, we plan to start working on a third (much larger and more mission-critical) user-facing Elixir service. A ballpark timeline for that third one would be getting it into production six months from now.
Our approach is generally to use new technology when we expect a specific benefit, not just because it's enjoyable. (Although it is certainly enjoyable!) So to the extent that we keep finding ways that doing more Elixir will benefit our code base, we'll keep doing more of it, but we're not going out of our way to rewrite Ruby code in Elixir without a tangible benefit in mind.
What are the next big things in store for Elm that you're excited about, what's it like writing Elm in Action, and what is the best way to start contributing to Elm (ex. Good starting places?)
What are the next big things in store for Elm that you're excited about?
Asset management - what Evan's working on right now - as well as the next release of
elm-test, and the improvements to the debugger Yosuke Torii has been working on.
There are also lots of smaller things I'm excited about, like union types becoming
comparable, which is vaguely in the pipeline somewhere, and broader coverage of the Web platform. So much awesome in the works! 😸
What's it like writing Elm in Action?
Time-consuming! It's swallowed just shy of my entire social life.
It's also one of the most rewarding projects I've ever worked on, so no regrets in committing to it. :)
What is the best way to start contributing to Elm (ex. Good starting places?)
Evan curates a list of projects at github.com/elm-lang/projects - but I'd also like to put in a shameless plug for elm-css - the CSS spec is huge, and there are lots of ways to improve our coverage of it!
Does this involve a focus on code splitting and/or techniques for lazy loading?
If you want to read about this, please check out the elm-dev mailing list. It's a google away :)
Awesome! Didn't know this was publicly discussed 👍
Thank you for the answers Richard! Looking forward to working more on Elm this year :)
What is the most difficult part about switching 100% to ELM?
Have you thought about going back to JS at some point (at least for an specific project)? I mean, maybe something was really complex/troublesome to build in ELM instead of Js?
Thank you!
Legacy code - there's rarely a good justification to porting really old code that doesn't get used anymore. (So we haven't really done it!)
Only for Node stuff, as Elm is only built for browsers right now.
For browsers, it's the opposite: I don't think I can ever go back. I can't predict the future or anything, but right now I have a really hard time seeing myself applying for a JS job ever again.
That was super quick!
Thanks Richard and thanks for pushing ELM forward <3
I just know that the Elm is a programming language but... I'm a frontend dev and I like anything related with the web browser platform... If you can give me an advice related to learn Elm vs MVVM frameworks (Angular, React, others less popular), RxJS why I should give a try?
The first chapter of Elm in Action is a free download, and I go into this question there.
Hope it helps!
Hi Richard!
I have used the Real World Elm demo as the basis of a project I am working on. So far it is working out really well, and I am happy with the structure and flow of the code.
The one area where I am struggling is providing application authentication. The demo provides authentication between the front-end and back-end, however, I need to protect enforce authentication at the front-end elm level.
How would you recommend handling this? Do you have demo code available that provides this type of authentication and routing?
Thanks,
Peter
Is there a board somewhere that Evan is posting packages he would like to see in Elm that he just can't get to. It would be great to contribute to the development of the environment.
There totally is! github.com/elm-lang/projects
What is your biggest pain point when writing Elm?
The pain point that leaps immediately into my mind is build tools. I'm not gonna sugarcoat it: Webpack has been slow and crashy and I can't wait for us to stop using it.
However, I'm assuming you meant "pain point specifically with Elm the language." For me it's definitely that union types are not
comparableyet. I really want to be able to use them as keys in a
Dictfor things like form validation. Unfortunately this is a ways off because the implementation requires modifying how Elm generates JS code to include a bit more information at runtime.
My #2 pain point is how much of the Web platform still requires interop to access. For example, if I could use an Elm library with a nice API that let me work with IndexedDB, I'd probably be up until 2am upgrading Dreamwriter.
Oh, and there's that
valuedoesn't Just Work the way it does in React. This is kind of inside baseball, but it can Just Work in React because
setStateupdates synchronously, whereas Elm does
requestAnimationFramebatching to improve performance. The alternative of
defaultValueworks fine for most use cases, but when it doesn't it's a big pain. I can conceive of a way to make
valueJust Work, but it would be a pretty invasive change for
elm-lang/virtual-dom.
Hm, interested in hearing more about the issue with
valueand how it's affected with
requestAnimationFramebatching. Is that to say if a text field isn't "bound" to the model with key presses, relying on the DOM to keep state, there will be inconsistencies?
Right - if you use
defaultValueto let the DOM's version of reality "take precedence" and use
onInputto listen for changes, it's all good.
Unless you actually need to manually override that value! Then it's a pain. 🙂
To expand on the Webpack issues:
I worked on this a bit to help fix it:
is it anti pattern to use Message like: UpdateModel (Model -> Model). When handling of the message is just to update model with function passed as parameter like:
case msg of
UpdateModel f -> (f model, Cmd.none)
.....
That seems overcomplicated, yeah. I wouldn't do that. :)
Since Elm seems to expose everything to the user, do you have a preferred method of keeping sensitive information from being presented? i.e. hiding API Keys
Have accomplished this with having a simple Python API set up parallel to the Elm app to feed Elm objects, but this seems overly complicated.
Yeah, for API keys I recommend creating something like
Secrets.elmand adding that file to
.gitignore. Locally, developers have to create that file as part of setting up their systems, and then you have your build process swap in a different file (containing different constants) for production builds.
This way you can easily access the secrets from any module, and if you forget to set them up locally, you'll get a compile error because the module won't be found!
I do this with the Frontend Masters workshop for GitHub API access tokens; you can check out the repo here github.com/rtfeldman/elm-workshop
Any advice for a team looking to incorporate Elm into a large React-based app who relies heavily on server side rendering (SSR) in Node? In a similar vein, do you have thoughts on apps that are SSR'd vs apps that are single page applications?
See dev.to/rtfeldman/i-am-the-author-o... regarding SSR in Elm.
My thoughts on SSR in general are "don't do extra work unless it's going to solve a problem you have." 😄
Richard, you've mentioned not receiving any runtime errors in Production. How often do you receive runtime errors in Development?
I haven't asked others on the team, but the only times I can recall seeing any in development, they weren't a surprise - e.g. I was mocking something up with Debug.crash with the goal of "I'll finish implementing this later, but for now I just want it to compile so I can try out the rest of what I've done" and then reaching one of the code paths that called Debug.crash as I was playing around with it.
Of course that's what I expected it to do, and naturally I replace every Debug.crash with a real implementation long before making a pull request!
As the ops guy at NRI responsible for Elm, the main source of errors with Elm is actually during builds. From 0.15-0.17, Elm did not correctly handle the caching of artifacts, leading to occasional compile errors that were not reproducable easily. It was simple enough to fix - just wipe the artifacts. But that also slowed the builds down a lot.
I'm also fairly certain I'm the leading expert on runtime exceptions in Elm - it's possible to make them happen, but most of the time you have to really understand Elm to make them happen. Unless you're using Array or Regex, of course. Both of these can lead to runtime exceptions - e.g
Regex.regex "[a". However, you'll not likely run into that in production - unless you are taking using input as regex input.. which probably isn't a good idea unless you're escaping things.
Thanks for the reply.
I think I must be unlucky then. I've been doing Elm for about 18 months and have observed 4 legit runtime exceptions (some bug with the compiler or the Array implementation, for example).
4 is still a super lower number for that time scale, but when an unexpected runtime exception does occur it's difficult to figure out what happened.
What's your favourite and worst part about Elm?
Favorite part (I'm gonna go with the American spelling, sorry!) is the feeling of invincibility when refactoring. I get some exciting idea for how to make my code cleaner, and I just do it. I don't worry about regressions, and lo and behold, when it all compiles again it still works! That feeling never seems to get old.
Worst part? Being smack dab in the middle of two communities that are almost polar opposites. Many people coming to Elm from JavaScript want Elm to be more like JavaScript, and many people coming from Haskell want Elm to be more like Haskell. I see Elm as its own thing—neither "JavaScript enhanced" nor "Haskell simplified"—and I've sometimes struggled to engage constructively with groups who don't see it the same way.
Does Evan work on NoRedInk work as well a building Elm or solely on Elm?
He only works on Elm. He's worked here for over a year and he's never touched our product repo. :)
How are you dealing with mobile device support at RedInk? And specifically touch?
Ps Thank you for taking the time to do this AMA!
About 25% of our users are on tablets, so we always have to keep touch in mind. When possible we've used pointer events (with polyfill) to keep things consistent, but that hasn't always been realistic for some drag-and-drop stuff. We haven't used any touch-related subscriptions yet.
It's still WIP, but you can see some non-polyfilled touch stuff we're doing in github.com/NoRedInk/drag-and-drop - which is already open source, but very unpolished at this point. For example, there's still more JS interop in there than there needs to be. 😄
How many companies are you aware of that use Elm in production?
I actually have no idea. I know the ones at the bottom of elm-lang.org do, but I keep hearing about new ones and being like "wait, you do?" and then forgetting their names. 😅
We should add more companies to that list :).
Where do you see the pros + cons of TEA? Especially, compared to Redux (used in combination with immutables).
I got into React very early after Facebook open-sourced it, but I switched to Elm before Redux came out...so I've never actually used Redux. :)
I think the following is the most honest way for me to answer the question of pros + cons:
The Elm Architecture in Elm
It's the only game in town. If you want to build UIs in Elm, the Elm Architecture is the only way to do so.
Pros: the entire ecosystem is optimized around it; no fragmentation
Cons: it's not well suited to doing major manual DOM manipulation
The Elm Architecture in JS
I've never tried this. JS is a totally different language, and I don't think it would be useful for me to guess what it might theoretically feel like to use Elm Architecture in JS. A better person to ask would be someone who's tried precisely this, and especially someone who's also tried Redux. :)
If the subtext here is "can I get many of Elm's benefits by using the Elm Architecture in JS?" the answer is unfortunately "not even remotely close." In my opinion almost all of Elm's benefits come from its compiler and library ecosystem, and you can't access either from JS.
Thanks you very much for your answer. No, I do not want to use the Elm Architecture in JS :)
To be more precise, I was wondering how the "update" function scales in the Elm Architecture, since I do not believe that Elm developers are using one big case statement for all possible messages. I think this is solved very well in Redux by composing reducers. I really dig the way all those small (pure) functions handle part of the application state. All the Elm example I saw didn't had that many messages, but I guess if your app grows you will also use some sort of composition to break the updates in smaller parts.
Ah! I posted my thoughts on this over on /r/elm - hope that's useful!
What's your favorite whiskey?
(hey, it's an ask me anything!)
Laphroaig Lore!
laphroaig.com/lore
Recommend you try Octomore if you have not had it before.
bruichladdich.com/octomore
What word is best used to refer to Elm developers and why is it Elmos?
I like Evan's preferred term: "Elm programmers"
I heard a great point once, which is that calling ourselves "Elmists" or "Elmers" or "Elmos" kind of suggests that we're a tribe, that we treat the language as more than a tool we use for a particular job.
But at the end of the day, that's what it is: a tool we use for a particular job! We should choose Elm when we think it's a good fit, and choose other tools when they're a better fit - not because we're part of a tribe. :)
Any plans for more talks in 2017?
Yep! My current plans for 2017:
Was there a CFP for September already?
Are there plans to move away from Javascript for Native code? If so, could you speculate on what Elm would look like post-JS?
Thanks!
What Noah said. 😄
There is definitely no solid plans for that. WebAssembly gets brought up and that might be a good idea one day but right now it's definitely not.
Where do you see the future of Elm and can you envision Elm becoming more mainstream? If so how do you feel the community can help make this happen?
Where do you see the future of Elm?
Someday I see it being an awesome back-end language too, but that's quite a ways off I think. With respect to the browser, I see the future of Elm being one where Elm's ecosystem becomes one of its biggest selling points.
Right now Elm's ecosystem is much smaller than JavaScript's, so ecosystem is a drawback overall. However, the overall quality of the Elm ecosystem is much higher - in terms of usability and reliability - than the (much larger!) JS ecosystem. I think this quality-over-size trend is likely to continue, because Elm's package manager has a blanket policy of accepting only Elm code, not JavaScript code.
As the gaps in the ecosystem fill in over time, I see the high-quality Elm ecosystem becoming a big selling point. Today people say "Elm's ecosystem is so small, you inevitably have to do some JS interop" but I think in the future people will say "Elm's ecosystem is big enough to meet all the needs of a typical web app, and it is so much nicer than the JS ecosystem."
We're not there yet, but we're headed in that direction. It will take time, but I think it'll absolutely be worth it. :)
Can you envision Elm becoming more mainstream?
Definitely. For any language aimed at industry use, I think success stories among industry early adopters are likely to predict long-term adoption. A very high percentage of Elm's early adopter stories are on the extreme end of positive.
I think the direction JS is moving is helping Elm out a lot. Virtual DOM libraries, type-checking, and functional programming concepts are all becoming more mainstream in JS, each of which narrows the familiarity gap between what people are using on JS teams and what they could be using if they introduced Elm.
How do you feel the community can help make this happen?
Posting experience reports. These are the biggest ways to help things become more mainstream, because people look for data points when making decisions about whether to dive into a language.
"I am thinking about trying Elm. Who else has done that? How did it go? Would the benefits help our team too? Did the costs seem like costs we can accept?" The more data points out there, the more easily people can make informed decisions about these things.
Our story at NoRedInk is out there, but do people know your story? If not, help them out by writing about it!
What do you think about such approach to structuring application with Return.Optics toast.al/posts/2016-10-20-optical-...
One of my favorite programming sayings is "I've learned there are worse things than boilerplate."
Over the years I've found that most things promising to "reduce boilerplate" do so in ways that make maintenance and debugging harder. I think back with regret on the times I decided to accept that tradeoff, and I think this falls under that category. I wouldn't recommend it. :)
What's the most unusual thing you've ever seen Elm used to do?
Pretty sure I saw someone (and I think it was you, but I could be misremembering) write Elm code to control a synthesizer!