How Rust Changed Me As A Developer
42 points by faassen
42 points by faassen
With love, bro could have been writing OCaml in 2004. One of Rust's greatest successes was getting into "mainstream" what functional languages had been doing for 20 years.
Or Erlang. There is so much in Rust that reminds me of it. Too bad Graydon Hoare did not stick to his guns on using only Erlang-style concurrency instead of error-prone mutexes and shared memory.
Would be a very different language if he had. I want to see that language, but I think Rust as it turned out is probably more important. It fills a niche that had been mostly unfilled, in a way that was revolutionary.
Will Gleam be that language (or at least a closer shade of it)?
Gleam has some similarities, but it has nothing like ownership and move semantics. If you consider those a core part of Rust, then Gleam is probably too far off.
Inko, at risk of sounding like an annoying door-to-door salesman, is much closer in that it very much tries to be what early Rust was going for. There are a few other Rust-like languages but as far as I know most of those focus more on the memory safety side of things through a complex but powerful type system, with less on a focus on cheap and sensible concurrency foundations/primitives.
There were safe languages before, like Ada, but yes, the borrow checker and lifetime checking approach is indeed revolutionary.
Keeping Erlang-style concurrency in Rust would have necessitated keeping green threads and a default async runtime, wouldn't it?
That's Go's approach, but you could imagine using OS threads without multiplexing, the only synchronization primitive allowed being queues (and Intel DLB even provides hardware support for them).
For most cases it would have been preferable to coloring functions. It's a shame that everyone has to pay the price for the few usecases where async is significant
On the contrary. Those who want Erlang style concurrency should be using Erlang, or Elixir. Those unwilling to pay the price of using Erlang or Elixir should be using Rust and are happy that Rust made the decisions that distinguish it from Erlang. Both languages are well designed and highly effective in their target domains.
To be honest, if Graydon had stuck to his guns, I likely wouldn't have jumped on Rust the moment v1.0 gave me a stability guarantee.
For me, https://www.hobofan.com/rust-interop/ is Rust's killer app.
I can write Rust libraries once, with the aid of monadic error handling, sum types, not having NULL, "make costs explicit", and so on, with the assurance that I'll never need to maintain two different versions in two different languages again so long as I avoid needing to depend on either single-process Go or parts of shared-hosting PHP sites that can't afford the cost of invoking a subprocess.
Rust is simultaneously...
x86_64-unknown-linux-musl, accepting more cross-compilation pain in exchange for none of the intolerable if err != nil boilerplate or at-the-time-missing support for generics. (Also useful for writing high-containment systemd services)ignore, image (God, is ImageMagick's syntax hard to remember for anything fancier than converting one format to another with default parameters), etc. etc. etc.QWidget-compatible Python/Rust equivalent to the QML/C++ stack via PyO3, Maturin, and mypy --strict. (Though I do wish someone would revive and complete Ritual as a memory-safe way for Rust to bind directly to the QWidget UI elements that even Kirigami is still too "re-skinned Android app" to replicate acceptably.)ALTER TABLE. (And, ideally, Django ORM's GenericForeignKey abstraction for more comfortably building a Django ecosystem. See previous entry.)A language is nothing without an ecosystem and even Rust isn't enough to fully get me off Python's ecosystem.
True, but I don't think it distracts from the point. There's a reason I recommend people learn Smalltalk, Haskell, Erlang, C, and a few others. It's not because those languages are the only languages that have the concepts that they rely on. It's not because those languages are widely deployed in industry. It's because they are good ways to learn specific styles of programming that will give you useful tools in other languages.
People who know Haskell and C, for example, write much better C++ than people who know just C, because they reach for the type language when it's useful and express useful compile-time properties in ways that are correct by construction. Haskell isn't the only language that will teach you this and I don't actually care if you learn, say, Idris (thought you will be more even sad if you have to move from Idris to C++ than you would if you came from Haskell), as long as you learn the concepts. And a language that's more widely deployed that teaches the same things is much easier to teach people.
I'd also say that, although I know many people who love it, I can't stand ML syntax. Even when I knew nothing at all about Rust other than some of the high-level claims, I never found Rust code particularly hard to read. I can go to a Rust codebase as someone who does not yet routinely write Rust and understand it. When I had to implement reader-writer locks on top of futexes a few months ago, I read a Rust implementation, understood how it worked, and why their approach made some assumptions that didn't quite align with what I needed. But reading ML requires a lot more work for me because it (like Haskell: this seems to be a thing FP encourages) aggressively goes for very concise (often single symbol) syntax that has little error correction. Sure, it's faster to type, but optimising for writing code rather than reading it is exactly the wrong thing to do.
Funny. One of the biggest turn offs of Rust to me is shedding its OCaml roots for something that is more verbose—unnecessarily, & “hard to read” for my tastes. It’s like how LiveScript was Scheme-related but Netscape management told its maker to call it JavaScript & look more like Java too despite users. You can sort of feel the FP roots in JavaScript, but the ergonomics make FP style end up being less ergonomic. I’m usually less of a fan of optimizing for familiarity (relative, experience-based) instead of simplicity. I say this struggling learning some concatenative programming recently as “everything is a word” should be as simple as “everything is a function” but I’m having to slog thru errors as it’s not hitting my FP/ML expectations—but I feel that struggle is my fault, not the language designer’s or the paradigm’s fault.
OCaml is less on the infix train than Haskell—even + isn’t generic over Numbers with + for integers & +. floats in OCaml—but Production™ Haskell doesn’t tend to be very infix heavy either unlike a weekend Haskell learning. But it’s hard to find Haskell ‘aggressively concise’ when there are array languages like APL & BQN (which aren’t built for purely code golf).
All return 10 by summing a sequence 1 to 4:
Rust
(1..=4).fold(0, |acc, x| acc + x)
OCaml
List.(init 4 ((+) 1) |> fold_left (+) 0)
Haskell
foldl1 (+) [1..4]
APL
+/ ⍳4
Factor
USING: ranges sequences
4 [1..b] sum
I recommend people learn Smalltalk, Haskell, Erlang, C, and a few others.
what are those "few others"?
As a counterpoint, I learned Haskell years before Rust. Haskell also has these powerful sum types, but in Haskell, everything just got in my way, the pure functions, the recursive list processing, the monads. I felt like the language interfered with my work, so much so that I didn't recognize the power of the type system. It was only when Rust came along that I really recognized the power of sum types. Long story short: Yes, it's true that other languages came up with designs found in Rust, but Rust combined them in a unique and robust way and also shipped well designed tooling like cargo to make the language approachable and facilitate learning new things. This led to people learning and appreciating paradigms that were new to them even though other languages had them for decades.
What I learned and am going to discuss here is not exclusive to Rust. You can encounter many of these concepts in other contexts, and indeed I had encountered quite a few of them already. But in this case, Rust helped bring them into better focus.
I indeed did not go into a historical treatment of functional programming concepts, but you might have noticed I used the term "sum types".
I was using Python, a non mainstream language at the time. I could have been writing C++ too for some of the other parts of Rust. But I didn't.
Learning Rust made me a better programmer in other languages. I too also read the code. Abstractions matter. Details matter.
Why write documentation?
The tooling and ecosystem on rust is top notch. Having examples that compile and run so they’re guaranteed to never be out of date is such a simple but powerful thing. Unit tests that live in the same file is another minor ergonomic win. Most weren’t done first by rust, but rust has them and they are great.
Rustfmt and clippy are wonderful tools, not to mention rust analyzer.
+1. One of my favorite posts on the matter is https://kobzol.github.io/rust/python/2023/05/20/writing-python-like-its-rust.html, which has definitely changed how I think about and structure basically all programs (but especially in Python). Is it less "pythonic"? Maybe. But it's also predictable and maintainable, which is worth a lot.
this scratches a nice part of my brain. related to the ownership -> clean architecture bit especially, though idt i ever realized this was something that might have resulted from writing rust.
to me, the rust compiler was the reason i got into formal methods, and decided to model the ownership rules in tla+ a few years ago as one of my first exercises..