Borrow checker is exclusively a strength of the language

547 points Dickonstruction

My background:

C programmer of 21 years, I've worked a lot on embedded systems, written custom kernel modules, implemented low level protocols, many made-to-order CLI tools, worked with asm back when there was actual work to be done down there and you could read entire asm documentation from a relatively thin book. I've also done a fair share of web dev in cpp.

So, my rebirth as a rustacean begins as I get called by a former client to work on a rust project, previously their stack was entirely cpp-based.

Well, I can say one thing for certain, despite being warned about borrow checker specifically (every time I dared talk to anyone who knows anything about rust), I am not fighting the borrow checker.

The reason is, that if you have a clear understanding of where your memory is at all times, how the stack works, how to first avoid dealing with the heap, then manage it correctly if you have to, what cloning/copying means, you do not actually have any unknowns.

The most important part for me was understanding what gets allocated on heap and what gets allocated on stack, and past that, things get relatively straightforward. Being extremely familiar with RAII helps, I guess.

Multithreading also works seamlessly, channels are great abstractions and much nicer to work with than anything c/cpp will give you. Also, there's a lot less possibility to get deadlocks which is very appreciated, because no matter how much experience you have, concurrency will be something your brain cannot easily handle.

IMO, the biggest reason people have so many issues with the borrow checker is that we've had literal decades of web programming dominance with languages like PHP, Ruby, Java, Python, C#, JS, that we've moved way too far from understanding memory.

Now it is coming to bite us when, twenty years ago, you literally could not do many of the jobs at the time reasonably well, should you have skipped on understanding how memory works.

I am probably still going to write a lot of c code as I have clients that aren't even considering rust (and it's hard to consider it when you have half a million lines of c99) but if there is any new project where I get to make a decision, I will invariably choose rust.

And it's exactly because of the borrow checker.

I does so much heavy lifting for me, it's incredible. Having the ability to get such a rich insight into what's going with your memory at compile time is quite incredible. It will warn me when I am about to do something stupid because I am distracted by trying to figure business logic, for instance.

What took hours or days of debugging in C, will now be resolved as soon as I get the red text telling me the memory I am pointing to shouldn't be there, when and where I am pointing at it.

My brain can be so much more relaxed because now I don't have to keep the entire memory model in my head, I can let rust do it, and when it compiles, it is like magic - somehow it always works correctly insofar my business logic is solid. Immutability by default is a great choice because mutating an already established struct that you're moving through several function calls is an exception, not a rule, and should be treated as such. Likewise, making something mutable being a deliberate choice means you are more likely to correctly solve the problem, because there is less friction.

I haven't gone too deeply into the rust community to really understand the sentiments about the borrow checker, but I've noticed that it's kind of a meme how borrow checker is annoying.

This is the spicy part of this take. I feel like this perspective comes exclusively from people who didn't do c/cpp, or from people who did, but never understood why things work or don't work, and kept rebuilding until it started working again.

I am saying this because over the years I've met many inexperienced engineers who, instead of learning things in depth, just tried to force through compile/link stage and hope things work, and when things "kinda work", they'd just record bugs to be taken care of, by someone more experienced, for the most part.

This approach doesn't let you compile in rust, but will instead teach you what you're doing wrong, and how to fix it. It's truly a marvel of engineering, and an amazing learning tool all by itself!

That'd be my 2c. I hope to make great things in rust!