Rex Kerr
2 min readFeb 13, 2025

--

The "weird mix of imperative and functional concepts" deserves to be in Rust's advantages, not drawbacks.

The thing is, Rust makes it as easy to write safe imperative code as safe functional code. Really! Almost always. While you're wrangling monad transformers and stacking your logic inside-out in for comprehensions in order to get the immutable logic right, you just go ahead and do what you want in Rust.

Well, except you can't, because Rust's borrow checker won't let you. You did it wrong, because mutability is hard. Mutability is hard. But monadic handling is also hard and the way you get it right is, in large part, to fight with the compiler until it typechecks (until you learn it well enough to get it right the first time). Same deal with Rust--you fight the compiler, it wins, and your code works (eventually, while you're learning; right away, when you get good at it).

Except it's mutable, and some things are way faster, and in most cases the logic is clearer. Save for frightful lifetime annotations (which really can get frightful), the ceremony of satisfying the borrow checker mostly doesn't impact the readability of the code, unlike having to sequence Seq[IO[Foo]] into IO[Seq[Foo]].

Now, that said, I still find Scala much more productive than Rust. Partly because of some of the other reasons, but also because I favor a direct style over a monadic style, which ends up being...a...weird mix of imperative and functional concepts, at the end of it.

But it's a really powerful mix. Better than Rust, as long as you can still lean heavily on immutable data. But not faster, and not better for safe mutability; there Rust still wins by a large margin.

--

--

Rex Kerr
Rex Kerr

Written by Rex Kerr

One who rejoices when everything is made as simple as possible, but no simpler. Sayer of things that may be wrong, but not so bad that they're not even wrong.

No responses yet