Rust rewired how I think as a developer
Rust changed me as a developer
After six years with Rust, four of them professional, the author argues that a language unlike what you know can reshape your mental toolbox. He credits Rust with finally making sum types click, with showing how enums can replace heavyweight interfaces, with clarifying the performance cost of dynamic dispatch, and with turning types into a design tool. The biggest surprise: macros deliver compile-time magic that Python does at runtime with pickle and Pydantic.
Any language without sum types now feels impoverished to me.
- bryanlarsen
A standard piece of advice is that every developer should do a major project in every big language family. A Lisp, an OO language, a functional language, Prolog, VHDL or Verilog, a Forth, et cetera. They'll all make you think differently and teach you lessons you will use outside of the family.
- dabinat
One of the things that I think makes Rust unique is that it acknowledges the possibility of human error. I think it’s also one of the most controversial too: there are certain people who get an ego hit at the insinuation that they ever could have written C code with mistakes.
Instead of hoping you remember to check for NULL, Rust forces you to make a decision on how to handle the possibility of failure. Sure, you can still pick a bad decision (unwrap) but that is at least a specific decision and you can’t forget to do it.
You can take it even further with things like the newtype pattern. If you have lots of numeric IDs (project ID, user ID, etc) you can give them distinct types so you don’t mix them up.
So Rust taught me I can program defensively against my own brain, which sometimes gets tired or lazy or distracted.
- JuniperMesos
> Any language without sum types now feels impoverished to me.
I wholeheartedly agree. I learned this lesson from learning Haskell, before I was even aware of Rust and before Rust had its 1.0 release. One of the reasons I was first excited about Rust in fact was precisely that it had a type system like that of Haskell.
- jan_m_savage
this has got to be the most beautifully designed blog I've read in a while. Esp the choice for code snippets.
also, the author is a great communicator who genuinely wants to convey his points in clear prose, instead of showing off their intellect (which seems to be the case in some other blogs)
- xeubie
Rust enums conflate the tag type with the union type that uses it. These should be separate things. In the example here, you can see that Rust gives no way to represent the tag type `{Human, Cat}`. In Zig there is an enum which is a set of tags, and a union which is backed by that enum and can have fields. It is obviously better to have these as separate concepts rather than conflating them. You often want the kind without the data, and Rust gives you no way to represent it. I'm not sure why I am bothering to rant about this but it's one of my biggest annoyances with the language.
- sedatk
It's ironic that these are the times of safety, but when C was getting popular in the 80's, it was the times of power. I clearly remember C was touted as being "so powerful that it lets you do anything without any checks". You were responsible to wield that power properly unlike more strict languages like Pascal, COBOL, or Fortran at the time, yet way more expressive than Assembly of course. Now, the pendulum seems to have swung to the other end.
- xiange
As a multilingual user, I think the best thing about Rust is that there aren’t as many hidden pitfalls.
- user20180120
Someone told me once, the spoken language you think in limits your thinking.
Guess it also applies to computer programming and hardware description languages.