How Rust Changed Me As A Developer

38 points by faassen a day ago on lobsters | 18 comments

icefox | 19 hours ago

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.

fazalmajid | 18 hours ago

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.

icefox | 13 hours ago

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.

travisgriggs | 12 hours ago

Will Gleam be that language (or at least a closer shade of it)?

yorickpeterse | 11 hours ago

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.

fazalmajid | 8 hours ago

There were safe languages before, like Ada, but yes, the borrow checker and lifetime checking approach is indeed revolutionary.

briankung | 14 hours ago

Keeping Erlang-style concurrency in Rust would have necessitated keeping green threads and a default async runtime, wouldn't it?

fazalmajid | 8 hours ago

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).

ptman | 14 hours ago

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

ghoti | 13 hours ago

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.

david_chisnall | 7 hours ago

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.

BenjaminRi | 6 hours ago

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.

[OP] faassen | 11 hours ago

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.

[OP] faassen | 11 hours ago

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.

schneems | 14 hours ago

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.

xavdid | 11 hours ago

+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..