News for hackers. Stuff that matters.
Re:The borrowchecker is what I like the least about Rust by noodletheworld on Saturday July 19, 2025 @07:58PM (#44620625)
> If you go out of bounds, Rust will panic and tell you exactly where it panicked

This arguement has a long history.

It is a widely used pattern in rust.

It is true that panics are memory safe, and there is nothing unsafe about having your own ref ids.

However, I believe thats its both fair and widely acknowledged that in general this approach is prone to bugs that cause panics for exactly this reason, and thats bad.

Just use Arc or Rc.

Or, an existing crate that implements a wrapper around it.

Its enormously unlikely that most applications need the performance of avoiding them, and very likely that if you are rolling your own, youll get caught up by edge cases.

This is a prime example of a rust antipattern.

You shouldnt be implementing it in your application code.

Re:The borrowchecker is what I like the least about Rust by teaearlgraycold on Saturday July 19, 2025 @08:33PM (#44620814)
I wish Rust had syntax or a directive to make Rcs a bit less obtrusive.
Re:The borrowchecker is what I like the least about Rust by ameliaquining on Saturday July 19, 2025 @09:09PM (#44620985)
Re:The borrowchecker is what I like the least about Rust by rnikander on Sunday July 20, 2025 @06:22AM (#44623654)
Interesting. My projects would benefit from those more convenient clones into closure captures. The other point where Rc is uglier than, say, Swift, is the explicit `.borrow()` and `.borrow_mut()` everywhere. I wonder if that could also be made more convenient/high-level without sacrificing the control over high performance (like C++) that got me to use Rust in the first place.
Re:The borrowchecker is what I like the least about Rust by zk4x on Sunday July 20, 2025 @01:11PM (#44627156)
Indices are the way to go for a whole range of programs - compilers (IR instructions), GUI (widgets), web browser (UI elements), databases, games (ECS), simulations, etc. It is however without borrowcheck guarantees.

Rc and Arc are definitely a bad way to avoid borrowchecker. GC is used because it is much faster than reference counting. OCaml and Go are experimenting with smarter local variable handling without GC. At that point they may outperform Arc and Rc heavy Rust code.