Asset minification with Elm (2018)
elm-lang.org
elm-lang.org
I wouldn't consider that a problem with Elm it's just that our users are mostly on desktop Chrome so we don't test very often on mobile Safari.
Do you have specific questions ?
What would you like to know? I love Elm. I'm absolutely hooked. I don't want to go back to doing Frontend work in JS, and I hope one day there can be an Elm-like experience for backend development as well.
Just off the top of my head a few bits of what I like about Elm: - You can actually write code, have no errors, and then move on, and never return to the project again. When I was doing JS, everyone I knew just took it for granted that you would be maintaining everything you ever wrote for the rest of your career. Not with Elm! You can actually finish projects and never return to them. - Its a simple and small language that is designed to interact with human beings. The compiler really talks to you instead of spitting out error codes or spaghetti. Apis and variables have human readable names instead of mathy terms of symbols. - For everything theres one way of doing things and the one way is usually really good. This strong consensus orientation of the Elm community means everyone is speaking the same language about every problem.
Gotta go, bye.
Haskell?
Haskell has a huge syntax and a ton of language features. It has a big ecosystem. Haskell is very mathy. Elm is the opposite in each of those regards.
How do you manage that? Migrating from 0.18 to 0.19 wasn't hard in my limited experience, but it wasn't "finish and never return" either.
You call it stateful tho. I dont know that drag and drop needs to be all that stateful. For drag and drop, the information your model needs is whether you have mouse-down-ed on something, the coordinates on the html element you mouse-down-ed, and the coordinates the mouse's current location is. 2 pairs of coordinates and a maybe type? Not too bad. I guess there is the code too, but at least the data is just few values, and not a complex and nested data structure.
On my team at work, we avoid state. Complex nested state is a big code smell for us.
https://reasonml.github.io/docs/en/what-and-why
I've really been digging slowly into ReasonML and the biggest gain I can see is that valid reason === valid ocaml (and there's some good server libraries out there for ocaml)
I also like that JSX is the templating language, not that it matters.
Also, have you had any success with manipulating Elm to output static HTML/CSS as well as JS? I know it can do it, but I've never been able to manipulate how it does it (most recent version I tried with: 0.18)
Regarding static html/css, I havent done that either, so I dont know about it.
ReasonML (OCaml) allows impure functions but the best practice is to stay pure whenever possible. It's a very pragmatic language so despite providing all the functional and immutable programming features, it allows you to cut through the bureaucracy if you need to.
1. Healthcare
Fall 2017, I started integrating Elm into an AngularJS application after experimenting with it on a couple of side projects. After a successful initial feature, I convinced the team to use it for new features. Another couple of developers helped to create the initial version until late 2018. We started in Elm 0.18 and converted it to 0.19. Now a sole part-time college student maintains and adds new features to it.
2. Transportation management
Since January 2019, I work on an Elm project, once again weaved into an existing AngularJS app, with ~34k lines of Elm code. I inherited it with no interaction from the previous developer. It looks like it was introduced in mid-2017 and is currently on Elm 0.19. Although it is not perfect, not always following best practices, it is much easier to maintain than anything I've worked on in the past. On JS apps, I've torn my hair out trying to figure out what is going on and attempting to add new features.
With Elm, I refactor daringly and rest more easily.
Please let me know if you have any specific questions.
Watching a simple example in the elm website, the codes make judicious use of new lines, would you say those 34k lines would represent 17K in js?
It's a blast, it's a wonderful developer experience, it's changed my life as a developer after having to fight with Angular and React and the myriad of tools you need to use to have a decent experience.
It would be difficult for me to consider a position where I would not use Elm anymore, and if I did it would have to satiate my thirst for functional programming by letting me work with other cool similar languages.
We migrated pretty easily from 0.18 to 0.19, we only had to import a bit of code here and there from libs that would not migrate or update where changes had been made, strong typing and the compiler made it a rather pleasant experience.
The only thing we did not do was migrate to an SPA ; the scope of the app was wide and the cost to achieve this was too high I guess.
Few pain points, amongst which:
- Sometimes you have to do something you would expect to find off-the-shelf (like a souped-up drop-down or a tag editing system) but it's ususally a matter of designing your ui well and can be fun (plus you get to really design the user experience).
- Sometimes you have to do a bit of JS for stuff that aren't designed in Elm (anymore, ie websockets) and use ports to communicate.
- If you're building incrementally, and make mistakes (over-design, useless code to conform to an unrequired philosophy, etc.) it's a good thing to sometimes challenge the bad old choices and get them smoothed down ; thankfully the compiler is your friend here too.
- The learning curve, especially if your team isn't fond of functional programming, can be daunting if you don't have an Elm advocate. That was me in my team, and we grew fond of it, but made quite a few beginners mistakes on the way. All very fixable though.
Well, that's about it ; if you want help getting people started and boosted on the functional programming paradigm, please have a look at my blog: it's Elm-centric, focusing on the most important functional programming concepts that'll get you up and running on what's happening there :) https://medium.com/wat-the-elm-ist And it might even explain what monads are ;)
Upgrades have been pretty painless, and each new release brings a new level of ease of use.
We have made some architectural mistakes as we have learned the language. And since it is a newer language there are not as many established conventions for code organization – but we are figuring out.
I've also written a bunch of small mathy apps, e.g. https://jxxcarlson.io/apps/
Elm has been a joy to work with.
The company now has 4 production projects with Elm as the sole frontend tech.
https://www.reddit.com/r/programming/comments/992qe5/elm_019...
A more meaningful comparison would be "we ported these actual production apps to Elm and here's the difference." Finding comparisons between languages like Elm and JS often feels like an exercise in microoptimization: I don't care if it can update the DOM 20% faster if React or Angular already does it within 16ms, or if the download time for my bundle is reduced by 50% if it already loads in 200ms for my 95th percentile. What's going to get me interested in tools like Elm are solutions for actual issues that I'm toiling over, like providing better tools for mocking in tests, ways to build custom lint rules that don't involve me becoming a metaprogramming expert, isomorphic rendering without heartache, etc.
But when its added on top of a really pleasant development experience then you don't really need to to think about it too much. All it really is saying is that you aren't paying for it with extra code bloat.. Which is a great thing!
If the goal is to convince me to learn a new language for the weekend and play with it, telling me how I can save 50kb isn't huge motivation. Seeing actual examples of real world benefits are compelling for me, not artificial samples.
… on your beefy 1st world country developer machine. But some of us are building websites and apps which are used by people in 3rd world countries, where CPUs are not as fast, RAM is not as plentiful, bandwidth costs more and latency is much higher.
It all comes down to what is the target user group. If I'm building an intranet app, where I know people will be using their local 10G LAN to load the page, and run it on their powerful office machines, then not even a 10MB bundle size would keep me up at night. But then there are projects for NGOs which need to be accessible in 3rd world countries and so my priorities shift.
Then refrain, eh?
How is 71% size reduction not a meaningful difference? You don't pay for bandwidth?
> What's going to get me interested in tools like Elm are solutions for actual issues that I'm toiling over, like providing better tools for mocking in tests
Basically: "I don't care about the user experience, I only care about my own developer experience".
Sad, really. Any performance impact is huge when you imagine the sheer number of devices that code will run on once it's published to the web. And the variety of devices - does it render within 16ms on an old Android phone? I'll bet it doesn't. And that KBs of download isn't just download time, it's parse time too. Again, an old device is going to be sluggish parsing JS.
Even if you're talking about 95th percentile, prioritising your own development comfort over the experience of that last 5th of users feels wrong to me.
(I write this as someone who mainly does TypeScript, but did a few months of paid Elm work. The main problems with Elm I see are the lack of jobs + as of 0.19 the hostile (NB technically, not personally) approach to those not aligned with Evan's direction for Elm).
> mocks in tests, lint rules, isomorphic
What, is that like the stuff that irked you this week? Elm has tons of stuff to offer, some drawbacks too.
- TEA (the elm architecture) -> Redux
- Elm compiler error messages -> Rust error messages
Elm's BDFL, according to his talks or his twitter account, seems to be a thinker, not a politician. Every new release brings something new. I wonder what 0.20 will be.
Elm giveth, and Elm taketh away. I remember seeing stories about how new Elm versions removed some bits of functionality available in the previous versions...
Upgrades since 0.17 have been pretty easy too - there is automated tooling that does the heavy lifting.
The more automatic stuff that can be caught by the compiler is usually a breeze, though.
But ... minification is totally relatable and "better error messages" is less-so. The problem with benchmarks is they over-emphasize things that are measurable. Honestly, I don't care as much about binary size as I do about, e.g. maintainability. But the latter is harder to quantify.
It's not Elm's fault they have to play that game. People search for, "fastest javascript framework" when maybe that's not what they actually want. Maybe all they want is a good friend.