What Elm and Rust Teach us About the Future

Martin Modrák on February 08, 2017

So I recently started programming in Elm and also did some stuff in Rust. Honestly, it was mostly a hype-driven decision, but the journey was def... [Read Full]
markdown guide
 

This is a great post, and I agree that tagged unions and exhaustive 'match' really do seem to help with corner cases. And I also love the fact that both languages forbid null and require the use of an Option-like type to represent possibly-missing values.

However, I found that Rust's borrow checker was mostly a struggle very early on, but that I quickly learned to design code in ways that made the borrow checker almost invisible on a day-to-day basis. For Rust, I think it's useful to distinguish between:

  1. The initial learning curve: fairly steep. This is definitely steep, especially for people who've never worked in C or C++, or who have zero experience with any kind of functional programming. I think that most people will only climb this learning curve if they have a real incentive.
  2. The difficulty of Rust on a day-to-day basis once learned: not bad at all. After a few weeks of working in Rust, I found it to be a surprisingly comfortable language. It takes me maybe twice as long the write Rust code as Ruby code, but the Rust code is a lot faster, I trust it more, and I can refactor Rust code very aggressively without fear of breaking things.

For me, the actual big limitation with Rust is that the third-party library support for "work" stuff is almost there but has the occasional corner case. I find that I produce a steady stream of minor PRs to Rust crates whenever I try to do something tricky in production. Happily, Rust library maintainers seem to be a pretty friendly bunch and they process most of my PRs quickly.

 

I've been working on a rust+elm project for some time now: A NES emulator written in rust with a debugger front-end written in Elm. Both languages are an absolute pleasure to work with. With elm in particular, I'm amazed at what I'm able to accomplish considering a web app of equal complexity written in any other browser-centric language/framework would have become a massive burden to maintain and add features to.

I really need to do a proper demo of this thing, but here's a crappy demo showing off the debugger front-end: youtu.be/5JlHSK6BeKI

 

Thanks for the article, really interesting food for thought. I especially liked the reference to "GOTO considered harmful, considered harmful". Seems ridiculous in hindsight.

I really like the ideas of functional languages. I wish people would come to realize that functional and object oriented programming are not opposites; they can form powerful alliances. Immutability and pure (side-effect free, idempotent) functions are extremely useful concepts. However, I do not necessarily need to go as far as Haskell to implement those (neither do I need to go as far as Java to do object orientation).

I have one major pain point with pretty much every functional langauge out there, be it Elm, Haskell, OCaml, you name it: The syntax. "Unreadable" does not even begin to describe it. Sure, the program just has 250 characters (not lines!) in total. But if I need 10 hours to figure out what it actually does, then how does this help anyone? It's about as far away from "literate programming" as you can possibly be. Elm and Rust are nightmares come alive in that regard as well, albeit each for different reasons. I can't help but get the feeling that those languages were not designed to be written, read or interpreted by humans. In that particular regard, they are no better (if not worse) than the assembly code they compile to.

 

You are confusing readability with familiarity here, to the point that it is almost a little bit insulting to people who enjoy ML style syntax. :-)

I do agree though, that (academic) Haskell code can be hard to read: highly abstract, lots of cryptic operators, single letter module imports. But this is a separate issue, not to be equated with language syntax.

 

Just to add something that other maybe found useful:

IntelliJ has a very well made plugin for rust that gives you syntax highlight and allows you to resolve cargo dependencies, also it can run cargo tasks and other stuff related to the day by day work in Rust.

It's a pain to have this super big IDE only to use Rust, but it's an start.

 

Somehow Reason reminds me a bit of Elm.

Its code is always fully typed and it has variants (tagged unions) that are a nice solution for many problems I faced with front-end development (i.e. Error, Loading, Success).

Its integration with existing JavaScript seems to be more straight forward than Elm's.

 

About Rust with MSVC:

Rust's compiler backend is always LLVM. The only difference between the GNU and MSVC Rust compilers that you can download for Windows is the version of libc that your program is linked to, and which ABI they use for repr(C) structs and extern functions.

 

Thanks for the note. I'll remove that sentence.

 

Really interesting post, thanks! Just out of interest, why would you recommend using decimal types for representing currency? I’ve always found this to be problematic with rounding etc.

 

Decimal types differ from floating-point types in that they have a fixed precision (both before and after the decimal point), mimicking the way human clerks work with numbers. There are even regulations for this: in my country (Czech Republic), the law requires/suggests (IANAL) you to compute money-related operations (interest, fees, ...) with four decimal digit precision and then round the final number to two decimal digits.

This contrasts with floating point operations, that don't have fixed precision and cannot represent some values precisely. For example, subtracting 0.01 from a large number may yield the same number, which may be acceptable in physics simulation, but is not acceptable in finance.

 

The formatting of the post seems broken midway in. Hard to follow because of that.

 

Sorry I think that was an issue on our end. I fixed it.

code of conduct - report abuse