News for hackers. Stuff that matters.
Re:My experience crafting an interpreter with Rust (2021) by BoardsOfCanada on Saturday March 25, 2023 @08:00PM (#35308932)
> I would often write huge refactorings thinking that they would be a solution to a borrow checker error, just to get another one at the end of the refactoring.

Yeah this can often be a problem because the borrow checker doesn't kick in until the refactoring is done and no other errors are left.

Re:My experience crafting an interpreter with Rust (2021) by winrid on Saturday March 25, 2023 @08:08PM (#35309004)
This was my experience too. Although, it's less of an issue now. It was definitely frustrating, though.
Re:My experience crafting an interpreter with Rust (2021) by pornel on Saturday March 25, 2023 @08:54PM (#35309376)
Proficiency in Rust requires learning what won't work, rather than trying various things until they compile. Borrow checking is a set of rules to design for, rather than an oracle to test against.

It does take time and effort to really internalize these rules. But eventually you should be able to have a mental model of how ownership and borrowing work; consider what owns the data, if it can be borrowed within statically known scopes, will it need to mix sharing and mutation, and then apply Rust-specific types and design patterns to match.

Conversely, there are things that you just can't do, like using temporary references for parent-child relationships. Knowing this will save you time from even trying.

Perhaps learning materials need to be more explicit about it. For example, I suspect lots of people are discovering the limitation of self-referential structs the hard way.

Re:My experience crafting an interpreter with Rust (2021) by jbrr25 on Sunday March 26, 2023 @02:39AM (#35311713)
Count me in. I was doing the advent of code and tried to solve one problem with a tree that had parent references. Much thinking was done trying to please the borrow checker with no results, add some inner mutability and I got stucked.

I agree that it should be more prominent in some place. I got most of my info about that in StackOverflow and I tried using a hashmap to simulate the tree structure, but I don't think I finished that one.