News for hackers. Stuff that matters.
Re:Stop Making Me Memorize the Borrow Checker by melvyn2 on Saturday November 16, 2024 @07:36PM (#42160909)
The borrow checker exists to force you to learn, rather than to let you skip learning. To make an analogy, I think it would be weird if I complained that I had to "memorize the rules" of the type checker rather than learning how to use types as intended.
Re:Stop Making Me Memorize the Borrow Checker by Pannoniae on Saturday November 16, 2024 @08:08PM (#42161088)
Fair enough, but the problem in this analogy is that this learning isn't always useful or productive in any way. This is more like doing arithmetic in a sort of maths notation where every result must be in base 12 and everything else must be in base 16. Sure, you can memorise the rules and the conversions but you aren't doing much useful with your life at that point.

Obviously, the borrow checker has uses in preventing a certain class of bugs, but it also destroys development velocity. Sometimes it's a good tradeoff (safety-critical systems, embedded, backends, etc.) and sometimes it's a square peg in a round hole (startups and gamedev where fast iteration is essential)

Re:Stop Making Me Memorize the Borrow Checker by Aurornis on Saturday November 16, 2024 @08:14PM (#42161120)
I don’t understand your analogy at all. The borrow checker doesn’t feel like doing math in base 12 once you internalize the rules. It should come as second nature for 95% of programming work, with the last 5% requiring some planning ahead that probably should be done anyway in a properly written program.
Re:Stop Making Me Memorize the Borrow Checker by kstrauser on Saturday November 16, 2024 @08:23PM (#42161179)
I think it destroys productivity if and only if you don’t roll with it and do things the Rusty way. If you write code with its idioms, it can be a huge productivity boost. Specifically, I can concentrate on fixing logic errors in my code instead of resource bookkeeping. When I refactor something, I know I didn’t accidentally forget to move alloc/free to the appropriate places for the new code: if my changes broke something, it’ll tell me.
Re:Stop Making Me Memorize the Borrow Checker by Aurornis on Saturday November 16, 2024 @08:26PM (#42161194)
Rust shouldn’t “destroy development velocity” once you’ve grasped the core concepts. There is some overhead to being explicit about how things are shared and kept, but that overhead diminishes with time as you internalize the rules.
Re:Stop Making Me Memorize the Borrow Checker by tsimionescu on Sunday November 17, 2024 @01:35AM (#42162391)
Not if you're iterating and have to make fundamental changes. Just like certain advanced type systems, encoding too much at compile time means you have to change a lot of code in unnecessary mechanical ways when the design constraints change, or when you discover them.

This is not a bad thing by the way, it's an extremely plausible design chocie, and is one that Rust made very clearly: rejecting not-entirely-correct programs is more important than running the parts that do work. Languages that want to optimize for prototyping will make the opposite choice, and that's fine too.

Re:Stop Making Me Memorize the Borrow Checker by Spivak on Saturday November 16, 2024 @08:34PM (#42161232)
If the borrow checker only errd on code with bugs you could call it learning. Or if it was only possible to express correct programs in the Rust language. But such a thing isn't possible in general so we accept the weaker condition, accepting a subset of all valid code that can be proven correct. The usability of the language goes with how big that subset is, and the OP is expressing frustration at the size of Rust's.

Rust isn't alone in this, languages with type hints are currently going through the same thing where the type-checker can't express certain types of valid programs and have to be expanded.

Re:Stop Making Me Memorize the Borrow Checker by chombier on Sunday November 17, 2024 @02:39AM (#42162609)
Besides, if you still want to skip learning there are escape hatches like Rc<RefCell> but these hint pretty strongly (e.g. clones everywhere) that something might be wrong somewhere.