3 ms·
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
by andrewflnr 4y ago
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.
- svnpenn 4y agothis 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.
- andrewflnr 4y agoWhatever. 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.
- svnpenn 4y agoon 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.
- andrewflnr 4y agoContrary to what exactly that I said?
- svnpenn 4y agoto 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.
- andrewflnr 4y agoAh, 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.
- svnpenn 4y agothey 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.
- Dylan16807 4y agoThe 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.
- andrewflnr 4y agoYeah, 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. :)
- kragen 4y agoFunctional 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?
- andrewflnr 4y agoI 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.
- kragen 4y agoThank 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.