News for hackers. Stuff that matters.
Re:Rust Is Hard, Or: The Misery of Mainstream Programming by viktorcode on Friday June 03, 2022 @02:54AM (#31605069)
I never got the point of having borrow checker in a single-threaded environment. Can someplace please explain its usefulness to me in that scenario?
Re:Rust Is Hard, Or: The Misery of Mainstream Programming by Twisol on Friday June 03, 2022 @03:41AM (#31605373)
The borrow checker statically prevents having mutation and aliasing at the same time. Aliasing is when two names refer to the same state; mutable aliases make it possible for "someone else" to act on that state while you're using it.

Consider the humble for-each loop:

    for (let x : xs) {
      xs.remove(0);
    }
If you're not careful, modifying a collection while you're traversing it can cause you to visit elements multiple times, or skip some elements entirely. There are effectively two tasks occurring at the same time -- interleaved, not parallel, but still concurrent: the ordered traversal and the action on each element. Both tasks can view the list, but one of them also modifies it behind the other's back.

This problem simply can't happen in Rust (without going out of your way, at least), because you can't independently mutate a list you're already iterating over.

Re:Rust Is Hard, Or: The Misery of Mainstream Programming by TheDong on Friday June 03, 2022 @03:12AM (#31605166)
Let me show you a bug in Go which involves no threads/goroutines, but would be solved by the borrow checker:

https://go.dev/play/p/sEptCgMM0Bh

In rust, you could not write that code without using either unsafe, or getting borrow checker errors.

Re:Rust Is Hard, Or: The Misery of Mainstream Programming by nickez on Friday June 03, 2022 @02:58AM (#31605091)
You avoid use after free for example