News for hackers. Stuff that matters.
Re:In Defense of Linked Lists by adeptima on Friday November 04, 2022 @05:24PM (#33473989)
When people asking my opinion for Rust, I loved to share them the Linkedin List implementation link: https://doc.rust-lang.org/src/alloc/collections/linked_list....

And the first feedback is why so many unsafe blocks? What is it Option<NonNull<Node<T>>> ? '_ ?

Another reason to share, if you can understand Linkedin List, you are free to code in Rust ;)

Re:In Defense of Linked Lists by SighMagi on Friday November 04, 2022 @05:41PM (#33474215)
There’s so much code marked “unsafe” in there…
Re:In Defense of Linked Lists by estebank on Friday November 04, 2022 @06:20PM (#33474715)
That's because in order to interact with pointers you need unsafe, and not using unsafe in Rust requires a single ownership tree or reference counting. If you're not keen on either of those solutions, you shouldn't be writing a Doubly Linked List in other languages either (because they will have either pointers or reference counting/GC).
Re:In Defense of Linked Lists by andrewflnr on Friday November 04, 2022 @06:58PM (#33475201)
"Those solutions" start off being hierarchical ownership or reference counting, but turn into "pointers or reference counting". Requiring pointers is implicit to the definition of linked lists, and calling it out here is silly. And you don't really need either ref counting (again, pretty obviously, witness every real world implementation) or hierarchical ownership outside Rust.

Conceptually, the list as a vague concept owns all the nodes. The ownership just stops being expressible directly through references the way Rust wants it to be. But you don't have to re-invent hierarchical ownership to implement DLLs in other languages, because it's not really there in the problem. You just have to accept that they're always going to suck under Rust's ownership model.

Re:In Defense of Linked Lists by estebank on Friday November 04, 2022 @07:36PM (#33475640)
> Requiring pointers is implicit to the definition of linked lists, and calling it out here is silly.

The usual complaints are that "Safe Rust doesn't let you do this", when unsafe Rust is right there to let you operate on any soup of pointers datastructure that you'd want to implement.

> you don't really need either ref counting (again, pretty obviously, witness every real world implementation)

If you implement DDL in a memory managed language, you effectively have the same behavior as you would in Rust with Arc or Rc. The ownership of the nodes then belongs to the GC or the RC value. You don't have to think about it because you're abstracted from the lifetime of each node by the language and runtime.

> or hierarchical ownership outside Rust

The ownership/borrow checker requires hierarchical to operate, but it doesn't stop you from writing unsafe Rust.

> Conceptually, the list as a vague concept owns all the nodes. The ownership just stops being expressible directly through references the way Rust wants it to be. But you don't have to re-invent hierarchical ownership to implement DLLs in other languages, because it's not really there in the problem. You just have to accept that they're always going to suck under Rust's ownership model.

Yeah, and that's what unsafe is for. Most code doesn't need vague ownership, though. I'd go as far as saying that the nudge towards clear ownership helps both maintainability and performance.

My concern is with the prevalence of this idea that unsafe Rust is not "real Rust" or that the existence and use of unsafe Rust somehow precludes any benefits of Rust.

Re:In Defense of Linked Lists by db48x on Friday November 04, 2022 @09:06PM (#33476544)
Technically the pointers don’t have to be actual pointers. And if they’re not actually pointers, then Rust’s ownership model and borrow checker will be perfectly content; they’ll barely trouble you at all. And you won’t even need any unsafe blocks.

What you do instead is use integers instead of pointers. The integers are indexes into a Vec of list nodes, owned by the linked list. Since the nodes are now owned only by the Vec, which is in turn owned only by the linked list, the borrow checker will not complain.

Some people object that this is cheating somehow, but what is memory but a giant untyped global vector, shared between all parts of your application? Pointers into that giant shared array are just indexes with extra risk, since you have to trust that they point to real nodes that have been initialized. Plus, you often see users of a linked list put the nodes into an arena allocator anyway, especially in the kernel. The Vec in your Rust implementation serves the same purpose as the arena allocator.

Re:In Defense of Linked Lists by andrewflnr on Sunday November 06, 2022 @01:03AM (#33489191)
> shared between all parts of your application... with extra risk

That's pretty important actually. I'd say it's a qualitative difference. :) But yeah, arenas are great.

Re:In Defense of Linked Lists by tracker1 on Friday November 04, 2022 @06:06PM (#33474547)
There be dragons...
Re:In Defense of Linked Lists by hnov on Friday November 04, 2022 @05:46PM (#33474273)
Isn't a doubly linked list basically incompatible with Rust's idea of memory ownership?
Re:In Defense of Linked Lists by proto_lambda on Friday November 04, 2022 @05:49PM (#33474324)
It's definitely not a data structure that makes the borrow checker happy. Luckily it's also not a data structure that's required or desirable in 99% of cases, but the standard library still offers an implementation for those 1% so people don't try to write their own (turns out getting a doubly linked list correct isn't quite as trivial as it may seem).
Re:In Defense of Linked Lists by Waterluvian on Friday November 04, 2022 @06:09PM (#33474569)
I’m actually a bit surprised it’s in the standard library if it’s so uncommonly needed. Isn’t Rust’s stdlib tiny with a philosophy of letting the community fill in most things?
Re:In Defense of Linked Lists by estebank on Friday November 04, 2022 @06:22PM (#33474733)
There were arguments made for its non-inclusion[1].

[1]: https://rust-unofficial.github.io/too-many-lists/sixth.html

Re:In Defense of Linked Lists by Waterluvian on Friday November 04, 2022 @06:29PM (#33474824)
I enjoyed reading this. A fun style.
Re:In Defense of Linked Lists by brundolf on Friday November 04, 2022 @06:06PM (#33474540)
It's at odds with it, but so are many other data structures found in the standard library. The solution is usually to use unsafe { } inside the data structure to allow those criss-crossing pointers (while exposing safe, checker-friendly interfaces to the outside world)

This is a great resource that outlines several different strategies for implementing linked lists in Rust: https://rust-unofficial.github.io/too-many-lists/

Re:In Defense of Linked Lists by zozbot234 on Friday November 04, 2022 @06:16PM (#33474667)
AIUI, GhostCell and related patterns can be used to implement doubly linked lists in safe Rust. These patterns are quite obscure and hard to use in practice, though.
Re:In Defense of Linked Lists by tmtvl on Friday November 04, 2022 @05:57PM (#33474426)
From what I remember Rust has some kind of RefCell with weak references. Those could be used to make DLLs, if anyone can find a reason to use those. That said, you could also use zippers...
Re:In Defense of Linked Lists by steveklabnik on Friday November 04, 2022 @06:08PM (#33474558)
RefCell<T> and weak references are two different things, but rust has both, yes.
Re:In Defense of Linked Lists by slaymaker1907 on Friday November 04, 2022 @06:05PM (#33474528)
Now imagine writing the drop implementation for a DLL that doesn't cause a stack overflow.
Re:In Defense of Linked Lists by dekhn on Friday November 04, 2022 @05:48PM (#33474312)
I don't know Rust but I would guess that an Option<NonNull<Node<T>>> would be a Node of type T, that cannot be set to null, but can be optional. This is a type I would want to return from a function that could either return nothing, or a pointer to a real thing.

As for the unsafety, I would assume the authors of collections know what they are doing and do that for performance.

Re:In Defense of Linked Lists by proto_lambda on Friday November 04, 2022 @05:51PM (#33474354)
`NonNull` is actually a wrapper around the pointer type, with the added invariant that the pointer cannot be null. The compiler is made aware of this, which allows `Option<NonNull<T>>` to be just a plain pointer, where the `None` variant of the option corresponds to a null pointer and the `Some(ptr)` case corresponds to a non-null pointer.
Re:In Defense of Linked Lists by josephg on Friday November 04, 2022 @06:36PM (#33474932)
I really wish rust had better syntax for this. Raw C pointers should probably all be Option<NonNull<T>> rather than *mut T.

The latter is easier to type but worse in almost every way. Ergonomics should guide you to the former, not the latter.

Re:In Defense of Linked Lists by andrewflnr on Friday November 04, 2022 @06:47PM (#33475059)
I think if you tried to do that, you'd basically be mixing type-driven optimizations with the C FFI, which sounds sketchy, to me at least. The null-optimization for Option is just that, an optimization, and I don't like taking it for granted where safety/security is at stake.
Re:In Defense of Linked Lists by josephg on Friday November 04, 2022 @07:54PM (#33475826)
Thats fair.

I suppose one problem with this approach for C FFI is that there's a lot of different values which could all be "null pointers". Converting them all for Option would be awkward and slow, and you wouldn't want to ever risk getting this stuff wrong.

But pointers are also useful even if you aren't doing FFI. Eg for implementing custom data structures. In that case, Option<NonNull<T>> (Or even NonNull<T>) is usually better than *mut T. But its harder to type, and it doesn't clearly tell you if the pointer should be *mut T or *const T. NonNull<T> should be preferred because security/safety is at stake for this sort of code.

Re:In Defense of Linked Lists by nickitolas on Friday November 04, 2022 @09:09PM (#33476568)
The layout is guaranteed and documented as thus: https://doc.rust-lang.org/std/option/#representation

> Rust guarantees to optimize the following types T such that Option<T> has the same size as T:

> - Box<U>

> - &U

> - &mut U

> - fn, extern "C" fn1

> - num::NonZero*

> - ptr::NonNull<U>

> - #[repr(transparent)] struct around one of the types in this list.

> This is called the “null pointer optimization” or NPO.

> It is further guaranteed that, for the cases above, one can mem::transmute from all valid values of T to Option<T> and from Some::<T>(_) to T (but transmuting None::<T> to T is undefined behaviour).

Although I'm not sure if the ABI is guaranteed to match (Which could differ even if the layout matches AFAIK). The ABI for Box is guaranteed to match since https://blog.rust-lang.org/2020/01/30/Rust-1.41.0.html , and I would imagine NonNull is the same. Maybe you could open an issue in the UCG asking if you're needing confirmation.

Re:In Defense of Linked Lists by kibwen on Friday November 04, 2022 @06:55PM (#33475163)
It's an interesting suggestion to impose Option semantics on raw pointers by default (presumably with some alternative way to receive a nullable pointer, for completeness). But in the meantime, in your own codebase, it's easy enough to do `type Ptr<T> = Option<NonNull<<T>>`.
Re:In Defense of Linked Lists by josephg on Saturday November 05, 2022 @02:28AM (#33478547)
The problem there is that NonNull is exclusively a wrapper around *mut T. Using it discards the distinction with *const _ pointers. I think that has implications for correctness with Miri.
Re:In Defense of Linked Lists by chlorion on Friday November 04, 2022 @06:17PM (#33474677)
Considering that unsafe rust basically just allows raw pointer access (see link below) which is already a thing you can do normally in C, I do not see how that's a very good argument against it honestly.

As for the Option type, it is exactly what it says. It's an optional, non-nullable node generic over type T. I suppose generics, optionals and the idea of non-nullable types might be exotic at first, but this is not a problem with Rust as much as it's a problem with C not being able to express these concepts in the first place and instead expecting you to spray null checks all over the place!

https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html

Re:In Defense of Linked Lists by scaramanga on Friday November 04, 2022 @09:47PM (#33476863)
Not to be overly contrary here but, you "need to spray null checks" probably just as much in rust as in C (in this specific example, not in general). Since those prev/next pointers are being modified in unsafe code where either you're using NonNull::new() which contains the null check, or you're using NonNull::new_unchecked() which means you need to convince yourself all the invariants hold true. The situation is roughly equal in C (ie. once you prove in a module that fields cannot be NULL, no need to add lots of redundant extra NULL checks in all users of the module).
Re:In Defense of Linked Lists by kibwen on Friday November 04, 2022 @06:26PM (#33474794)
When explaining why the difficulty of modeling linked lists in Rust doesn't matter, I like to share the following book, "Learn Rust With Entirely Too Many Linked Lists", written by the woman who wrote the implementation you've linked above: https://rust-unofficial.github.io/too-many-lists/
Re:In Defense of Linked Lists by keepquestioning on Friday November 04, 2022 @06:27PM (#33474806)
I read this and noped out of learning Rust.
Re:In Defense of Linked Lists by kelnos on Friday November 04, 2022 @07:00PM (#33475221)
So I glanced at it, expecting something much much worse, but I was surprised to see it wasn't that bad. Even if you look at the final code for the final implementation, it doesn't seem much more complex than what you'd have to write in C. And a good chunk of the code is implementing traits from the stdlib, stuff that isn't strictly necessary, but makes it easier to make the API of the deque idiomatic and work well with other stdlib (and non-stdlib) APIs.

And regardless, this book is teaching from the perspective of intentional super-hard-mode. Most Rust developers will never have to write that much unsafe code.

Re:In Defense of Linked Lists by hinkley on Saturday November 05, 2022 @12:41PM (#33483090)
Are you bragging about self imposed ignorance of advanced programming topics?

I guess there’s plenty of space in the world for PHP programmers and their predecessors, the VB programmers. So… congrats?

Re:In Defense of Linked Lists by adeptima on Saturday November 05, 2022 @08:36AM (#33480825)
My first thought it was a joke ... ;)

Learn Rust with entirely too many linked lists (2019) - https://news.ycombinator.com/item?id=22390662 - https://rust-unofficial.github.io/too-many-lists/index.html

In this series I will teach you basic and advanced Rust programming entirely by having you implement 6 linked lists. In doing so, you should learn:

- The following pointer types: &, &mut, Box, Rc, Arc, const, mut, NonNull(?)

- Ownership, borrowing, inherited mutability, interior mutability, Copy

- All The Keywords: struct, enum, fn, pub, impl, use, ...

- Pattern matching, generics, destructors

- Testing, installing new toolchains, using miri

- Unsafe Rust: raw pointers, aliasing, stacked borrows, UnsafeCell, variance

Re:In Defense of Linked Lists by andrewflnr on Friday November 04, 2022 @06:39PM (#33474971)
In the Rust ecosystem philosophy, linked lists are the kind of thing you want to write once, very carefully, then re-use a lot. That's exactly the kind of code where unsafe can be reasonable. It's not like it would actually be safer in any other language that didn't have an explicit unsafe keyword. More aesthetically pleasing, perhaps, but not safer.

You're acting like it's some epic burn on Rust that there's some ugly code in its stdlib. It's not. Stdlibs are like that. Furthermore, as others have pointed out, linked lists in particular are a pathological case for Rust, meaning you're pointing and snickering at a special case of a special case. Most people never have to write or look at that kind of code.

Re:In Defense of Linked Lists by svnpenn on Friday November 04, 2022 @06:48PM (#33475082)
this comes off as extremely defensive. I don't feel like the person you're responding to, intended any kind of "sick burn". Calm down dude.
Re:In Defense of Linked Lists by andrewflnr on Friday November 04, 2022 @07:06PM (#33475297)
Whatever. They're definitely pointing and snickering. I don't think there's any way to read their post but as a criticism of Rust the language based on this one piece of stdlib code, and that's nonsense. That irritates me. So sue me.

There are reasonable arguments to be had about Rust. I wish people would do those instead of all the nonsense you usually see.

Re:In Defense of Linked Lists by svnpenn on Friday November 04, 2022 @08:01PM (#33475915)
on the contrary, I think more and more people are unwilling to hear any criticism, even constructive criticism, of "their thing".

Rust is not perfect. I wont go into its faults, but you know what they are. I think overall, Rust is a great language, but you have to be realistic and understand that some stuff you ignore in favor of the holistic view, others might not be able to. So sometimes maybe just take the criticism and deal with it, or if you're in the position, do something to fix the problem.

Re:In Defense of Linked Lists by andrewflnr on Friday November 04, 2022 @09:33PM (#33476744)
Contrary to what exactly that I said?
Re:In Defense of Linked Lists by svnpenn on Friday November 04, 2022 @09:54PM (#33476912)
to this:

> I wish people would do those instead of all the nonsense you usually see

you seem to want to place the blame squarely on the critics, when the reality is that many people in your position are seemingly intolerant of any criticism of "their thing", even constructive criticism.

Re:In Defense of Linked Lists by andrewflnr on Saturday November 05, 2022 @12:00PM (#33482692)
Ah, I see, since I'm defending Rust in this sub-thread, it's impossible for me to ask for constructive criticism instead of bullshit without it being "seemingly intolerant", while you're the reasonable one for doing the exact same thing. Basically just assuming I'm an idiot and/or arguing in bad faith. Lovely.
Re:In Defense of Linked Lists by svnpenn on Saturday November 05, 2022 @12:22PM (#33482922)
they linked to the source code. What bar do they have to reach, before you honor it with being constructive? the point is, there is no bar. unless its praise to Rust, then its trolling in your eyes.
Re:In Defense of Linked Lists by Dylan16807 on Saturday November 05, 2022 @04:57PM (#33485649)
The source code of the standard library is usually an awful way to show off any language. Pointing and gawking at such a thing as criticism is very bad criticism.
Re:In Defense of Linked Lists by andrewflnr on Saturday November 05, 2022 @06:56PM (#33486821)
Yeah, I already made that point in my root comment. It was pretty much my whole thesis, in fact. Doesn't matter, apparently! svnpenn is determined to confuse me for someone dumber. :)
Re:In Defense of Linked Lists by kragen on Saturday November 05, 2022 @12:14AM (#33477893)
Functional programming languages like Haskell, ML, and Lisps use linked lists very extensively and rarely have safety problems as a result. On the contrary, because linked lists allow you to build a list up efficiently without mutation, they give you a good way to avoid all the safety problems that come from mutation. In general just about any kind of data structure in these languages is some sort of weird linked list.

This isn't the best solution for all cases! Sometimes performance is more important than safety, and there are things you can't do as efficiently without mutable data. And sometimes (especially for systems that are reactive rather than transformational, in Harel and Pnueli's terms, or for libraries) a garbage collector is an unacceptable cost.

And Rust is actually reasonably good at singly-linked lists; it's just doubly-linked lists (which inherently feature mutation) that are troublesome. Singly-linked lists with sharing through Arc are a little more expensive in Rust than in something like GHC, Ikarus Scheme, or OCaml, but that's hardly a damning criticism of Rust.

But you seem to be claiming that linked lists are unsafe in any language, and to anyone familiar with functional programming, that claim is obvious nonsense. Did you intend it?

Re:In Defense of Linked Lists by andrewflnr on Saturday November 05, 2022 @12:10PM (#33482803)
I should have been more specific about doubly linked lists. And I think the implicit context for comparisons with Rust is usually pointer-heavy non-GC languages, especially given OP, but maybe I should have specified that, too. It's certainly true that DLL's are tricky to write, and tricky to mechanically prove correct, which is mainly what 'unsafe' actually means.
Re:In Defense of Linked Lists by kragen on Saturday November 05, 2022 @04:51PM (#33485558)
Thank you for clarifying!

I would think that the implicit context for safety comparisons with Rust would be other languages designed with safety as a goal. Those languages are almost all GCed! ML, Haskell, Scheme, Oberon, Coq, Erlang — all GCed. That's because GC helps enormously with type- and memory-safety. In the example in question, it ensures that your doubly-linked list manipulation cannot cause undetected type errors, use-after-free errors, double-free errors, or memory leaks; this last guarantee goes beyond what Rust can offer in this case. In ML, Haskell, and Oberon, it even ensures that all type errors are detected at compile time instead of run time.

There are a few languages designed with safety as a goal that do not normally use GC: Pascal, Ada, COBOL, and MISRA C. But they suffer enormously in expressivity, are not pointer-heavy, and are generally only viable alternatives in restricted domains.

The usual pointer-heavy non-GC languages are C and C++, and these have no concern whatsoever for safety, so it seems like a weak-man argument to target linked-list manipulation in them as unsafe relative to Rust.

The correctness criteria for doubly-linked lists are indeed not within the capability of Rust's (or Haskell's, or ML's, or Oberon's) static checking. That doesn't imply that it's impossible to statically verify doubly-linked-list manipulation code, and in fact I think Ada SPARK is capable of doing it. Certainly it's within the scope of what you can prove with Coq or Isabelle/HOL.

Re:In Defense of Linked Lists by andrewflnr on Saturday November 05, 2022 @07:28PM (#33487040)
I did say tricky, not impossible. ;) IIRC proving pointer-pushing code is an active research area, but I could easily be out of date. Not cheap enough to be mainstream yet, anyway.

We're deep into semantics territory with "what's the right context for comparing Rust", but I would strongly argue that yet another language safe via GC is not interesting for its safety. As you point out, it's been done a lot. Rust is interesting because it pushes safety into a new level of runtime performance and (to some extent) lower hardware abstraction. AIUI that's the motivation for Rust, where most of the marketing and enthusiasm is, etc. And if you don't need that speed/control, Rust isn't much of an improvement: just use a GC and have more fun (unless you just think Rust is neat, I guess, but whatever).

So it's the languages already in that "low level" domain (broadly defined) that are its real competition IMO, C/C++, upstarts like Zig/Nim/Crystal, etc, languages where linked lists are on the cards. Especially for the problems where safety has previously been seen as too costly in either runtime or development time (no one is coding to fast moving web standards in Ada/SPARK, methinks).

And I don't think I implied that those languages' list manipulation is less safe than Rust's, rather that Rust's isn't any worse, besides being uglier. I made almost the same point from the other direction in another sub-thread: there's no use denying that Rust code for DLL's is uglier for no safety benefit on that particular task.

As others have pointed out, the whole question of linked lists in Rust is a huge distraction from its actual benefits and weaknesses.

Re:In Defense of Linked Lists by kragen on Saturday November 05, 2022 @08:36PM (#33487484)
Well, Rust can offer some kinds of guarantees that GCed languages can't, in the cases where its type system applies. It can allow you to safely share mutable data between threads, for example, or to guarantee that opened files get closed in a timely way. So I don't think it's interesting only because it pushes safety into a new level of runtime performance, though often that is also true.

I think it's noteworthy that, not only in the doubly-linked-list case but even in cases that use Arc (which doesn't require `unsafe`), Rust is less safe than mainstream GCed languages like Java (and arguably Haskell and OCaml). Rust can leak memory; those other languages can't. Its safety guarantees in those cases are a proper subset of theirs.

Unless I'm misunderstanding the situation? I've only written very small amounts of Rust.

Re:In Defense of Linked Lists by andrewflnr on Sunday November 06, 2022 @12:46AM (#33489078)
Fair point about other kinds of guarantees, I suppose. Now that you mention it, there has been some speculation about what a GC'd Rust would offer (worth remembering that IIRC early versions of Rust had a GC, until they figured out they could do without it). However I don't think that significantly changes my main point about where Rust primarily competes today, and its primary value proposition.

Re safety: Rust has, um, a very specific idea of what "safety" means. It's basically things that could cause RCE, or at least incorrect writes I guess. Memory leaks are specifically not considered "unsafe". :) And really, the worst you can do with a memory leak is DoS, until the target reboots. Handling mutable data across threads is included, though, which Java at least is somewhat famously not great at; it's really easy to write Baby's First Race Condition Demo in Java. So it feels really weird to say Rust's safety guarantees are a strict subset of Java's.

OTOH I agree it's hard to imagine Rust beating out Haskell for raw safety guarantees by any measure, and I have no idea for OCaml (despite having written a lot more Ocaml, heh).

Re:In Defense of Linked Lists by nemothekid on Friday November 04, 2022 @06:50PM (#33475105)
>When people asking my opinion for Rust, I loved to share them the Linkedin List implementation link:

This LinkedList obsession is a bit bizarre to me, and tends to come from older programmers who come from a time when coding interviews involved writing linked lists and balancing b-trees. To me though it also represents the stubbornness of C programmers who refuse to consider things like growable vectors a solved problem. My reaction to the LinkedList coders is not "well Rust needs to maintain ownership", its why does your benchmark for how easy a language is involve how easy it is to fuck around with raw pointers?.

LinkedLists are a tool, but to C programmers that are an invaluable fundamental building block that shows up early in any C programmers education due to how simple they are to implement and the wide range of use cases they can be used for. But they are technically an unsafe data structure and if you willing to let some of that stubbornness go and finally accept some guard rails, you have to be able to see that a data structure like linkedlists will be harder to implement.

It has nothing to do with the language; implementing with LinkedLists with any sort of guardrails adds a ton of complexity, either up front (e.g. borrowchecker) or behind the scenes (e.g. a garbage collector). When you accept this fact, it becomes ludicrous to imply that a LinkedList implementation is a good benchmark for the ergonomics of a language like Rust.

Re:In Defense of Linked Lists by bjourne on Friday November 04, 2022 @07:15PM (#33475422)
Wtf? That code looks like shit.
Re:In Defense of Linked Lists by mastax on Friday November 04, 2022 @07:52PM (#33475807)
C++'s STL linked list for comparison (libcxx).

https://github.com/llvm-mirror/libcxx/blob/master/include/li...

Re:In Defense of Linked Lists by kortex on Friday November 04, 2022 @08:09PM (#33476011)
Oof. Yeah, standard lib code tends to be harder to read on average than application code. But at least I can mentally parse the Rust code. Heck it even looks like a linked list impl. The c++ code looks barely better than line noise. I'm sure I could wrap my head around it, but ho boy, it's far worse than Rust by a long shot.

And this is with several years cpp experience, and maybe a few months of Rust on and off.

Re:In Defense of Linked Lists by einpoklum on Friday November 04, 2022 @08:31PM (#33476219)
Rust's list only supports a default allocation mechanism. For an actual comparison, you'll want to show us a Rust implementation which is parametrized over allocators.

Having said that - yes, it's not pretty. About the same length though.

Re:In Defense of Linked Lists by mastax on Friday November 04, 2022 @08:38PM (#33476294)
Adding allocator support does add a bit more noise:

https://github.com/rust-lang/rust/pull/103093/files#diff-8bd...

Re:In Defense of Linked Lists by riwsky on Friday November 04, 2022 @08:03PM (#33475949)
Also the implementation is all wrong. The proper way to add an element to a linkedin list is to send the element an email titled "I just requested to connect", along with a "view profile" and "accept" link.
Re:In Defense of Linked Lists by xdavidliu on Friday November 04, 2022 @08:09PM (#33476010)
> I loved to share them the Linkedin List implementation ... if you can understand Linkedin List ...

is the "In" in "LinkedIn" deliberate here or just a typo that was made twice?