News for hackers. Stuff that matters.
Re:Null References: The Billion Dollar Mistake by zozbot234 on Saturday January 11, 2020 @09:47AM (#22020117)
> there's even a book teaching how to implement doubly linked lists in Rust [1]

Doubly-linked lists are an awkward example because the "safety" of a doubly-linked list as a data structure involves fairly complex invariants that Rust can't even keep track of at this point, much less check independently. These things are exactly why the unsafe{} escape-hatch exists and is actively supported. But just looking at the amount of unsafe code in common Rust projects should suffice to figure out that this is not the common case, at all.

> At the same time, people are using Rust to build non-systems programs, where other languages would be more appropriate (e.g. those with garbage collectors).

Garbage collectors are good for one thing, and one thing only: keeping track of complex, spaghetti-like reference graphs where cycles, etc. can arise, perhaps even as a side effect of, say, implementing some concurrency-related pattern. Everything else is most likely better dealt with by a Rust-like system with optional support for reference counted data.

That's without even mentioning the other advantages that a Rust-like ownership system provides over a GC-only language. See e.g. https://llogiq.github.io/2020/01/10/rustvsgc.html this recent post for some nice examples.

Re:Null References: The Billion Dollar Mistake by amelius on Saturday January 11, 2020 @10:55PM (#22024352)
> Doubly-linked lists are an awkward example because the "safety" of a doubly-linked list as a data structure involves fairly complex invariants that Rust can't even keep track of at this point.

Perhaps it's just me, but I'd like to assume that my language does not treat any algorithm found in a basic algorithms course (e.g. Sedgewick) as awkward.

Re:Null References: The Billion Dollar Mistake by jayd16 on Saturday January 11, 2020 @11:18PM (#22024447)
Eh, I have no problem with the idea that data structures that work in C are awkward in different paradigms. Many data structures are awkward in functional programming. Lots of things are awkward in C that are easier in other languages.
Re:Null References: The Billion Dollar Mistake by elcritch on Sunday January 12, 2020 @08:15AM (#22026152)
How times have you used doubly liked lists outside a CS101 programming exercise? Even if you did, it’d usually be trivial to implement an array index version or just use unsafe. Basically it seems you give up almost nothing for memory safety.
Re:Null References: The Billion Dollar Mistake by dpbriggs on Saturday January 11, 2020 @11:22PM (#22024462)
For sure, you can avoid awkwardness by not statically verifying memory usage & invariants (c++, etc) or using a GC'd language. Rust's ownership and borrowing rules are limited, but simple enough for someone to internalize them quickly.

There's a pretty vast difference between human simple and computer simple. Rust requires that you prove memory safety, or use unsafe. That's a different problem than just informally ensuring invariants are met.

You could probably pull in more advanced type theory research for more nuanced ownership, but I'd bet the language would be harder to understand overall (Haskell disease).

Re:Null References: The Billion Dollar Mistake by empath75 on Saturday January 11, 2020 @06:36PM (#22023232)
I’m a rust fan, but garbage collection is about removing having to think about memory management from the developer almost entirely, not about performance.
Re:Null References: The Billion Dollar Mistake by perl4ever on Wednesday January 15, 2020 @12:58AM (#22052056)
I don't do the sort of programming recently where it matters, but when I read the debates on GC on HN, I think, why not a language where there is a GC, but it is "cooperatively scheduled" - you explicitly invoke it for a fixed amount of time. Wouldn't that be the best of both worlds?
Re:Null References: The Billion Dollar Mistake by bitwize on Saturday January 11, 2020 @06:43PM (#22023269)
Value and move semantics do the same thing and work in 90% of the cases a GC does. For the remainder there's ARC.
Re:Null References: The Billion Dollar Mistake by empath75 on Saturday January 11, 2020 @07:09PM (#22023392)
If you think rust eliminates the need to think about it in the way that python does, I don’t know what to tell you.
Re:Null References: The Billion Dollar Mistake by bluejekyll on Saturday January 11, 2020 @09:43PM (#22024114)
You might be reading too much into that comment.

Python allows you to do something with memory that Rust has made it a priority to be more concerned with, and that’s sharing.

C also has easily shared memory, much like Python. Point being that Rust wants to make sure that your references are safe to share, whereas Python wants you to share as much as possible and makes it safe by not allowing multiple threads to interact with it.

These are different trade offs, but Rust does allow you to forget about memory management in the same way Python does, but forces you to think how it’s being shared.

That’s the added cost over Python and the extra thought that goes into using the language.

Re:Null References: The Billion Dollar Mistake by tsimionescu on Sunday January 12, 2020 @03:45AM (#22025226)
No, having to think about value and move semantics is extra overhead you take on. It's better when the compiler can help you catch this, like in Rust, but it still forces you to structure your program a certain way and to constantly think about incidental details like ownership.
Re:Null References: The Billion Dollar Mistake by jayd16 on Saturday January 11, 2020 @11:13PM (#22024427)
GCs are also good at compacting heaps.
Re:Null References: The Billion Dollar Mistake by zozbot234 on Saturday January 11, 2020 @11:30PM (#22024484)
Perhaps, but at pretty severe cost. Your heap must be structured in a way that the tracing routine can make sense of (and the consequences of this involve considerable waste and inefficiency in practice - lots and lots of gratuitous pointer chasing), and the compacting step itself involves a lot of traffic on the memory bus that trashes your caches and hogs precious memory bandwidth.

Forget it. Obligate GC is a terrible idea unless you really, really, really know what you're doing.