Hacker News new | ask | show | jobs
by neilv 2544 days ago
> When writing Rust one comes to learn the code that the compiler likes, and strives to write code that is free of compiler errors in the first place.

I suggested that possibility, but is it generally true, or something personally true for you, or are you advocating that it would be good if people did that?

2 comments

When I started learning Rust and low-level programming (I'm coming from Ruby), spamming/searching for error/fixing code and wait for `cargo build` to turn green was the strategy I used. As I have more experience with Rust I become more and more aware of ownership/lifetime of everything I'm using, the compiler errors appear less and less, most of the time it's typo or mut missing now and not lifetime issues anymore.

So yes, if you work enough with the borrow checker, your brain will form another logical one, and that one you can use for writing C/C++ code. I have much more confident now in learning/writing C/C++ than before I learn Rust, because I feel like I can form a Rust-like design (tree-based, clear ownership/lifetime objects) and put that in using C/C++ syntax.

Definitely recommend using Rust as stepping stone to learn production-grade level C/C++.

I personally think it’s more nuanced than either of these. I do blindly type stuff in, and lean on the compiler to help me. At the same time, as I got more proficient, my initial code is closer to correct and produces far less errors.