- cross-posted to:
- programming
- [email protected]
- cross-posted to:
- programming
- [email protected]
Turn on all clippy lints on day one – even the pedantic ones. Run the linter and follow the suggestions religiously. Don’t skip that step once your program compiles.
There’s a bunch of clippy groups to enable, but IME the pedantic ones can be kinda … not what you want. Especially the one about unnecessary moves annoy me, as it suggests what I consider an unnecessary long lifetime for a value instead.
TIL about
clippy::cargo
. Thanks!
As someone whose only other language was very beginner-level Python before learning Rust, the part about not treating the borrow checker as an adversary, but as a companion, mirrors the point at which I began rapidly improving.
I like to say that the Rust compiler rules are like having a senior engineer over your shoulders to help you avoid writing (certain kinds of) bad code.
There are still times when the borrow checker becomes my adversary (like needing to share data in threads), and it is painful, but they become less frequent over time.
Yep. One reason why those situations become less frequent over time is that one learns to avoid such designs. Thought process: “Sharing data across threads is annoying. So I’d rather avoid it. Maybe message passing can solve the same problem as well?”
I just use
Arc::clone()
now that I know I can just throw the problematic data types on the heap easily. I’m sure there are “better” ways to do it, but¯\_(ツ)_/¯
Some people might dismiss Rust as being “unelegant” or “ugly”, but the verbosity actually serves a good purpose and is immensely helpful for building large-scale applications:
Here rust is trying to be unambiguous by forcing you to write just enough context when needed. It is not unnecessarily verbose at all and is not trying to be absolutely explicit about everything. When there could be more ambiguity, rust errs on the side of being more explicit which increases the verbosity. But when it is less ambiguous then it favors being less explicit. Hence why you can omit types and lifetimes in most situations but require them when it is not obvious what they should be.
I’m not new to Rust, but still a novice. And already loving the first point you make. This article is great (so far).
Pretty good read. Nothing very surprising and I might make the same kind of recommendations. I would have tried to phrase several things with less prejudice, though.