6 ms·
Please explain the differences in typical aliasing rules between C and Rust. And please explain posts like https://chadaustin.me/2024/10/intrusive-linked-list-
by disappoint 10mo ago
Please explain the differences in typical aliasing rules between C and Rust. And please explain posts like
https://chadaustin.me/2024/10/intrusive-linked-list-in-rust/ https://chadaustin.me/2024/10/intrusive-linked-list-in-rust/
https://news.ycombinator.com/item?id=41947921 https://news.ycombinator.com/item?id=41947921
https://lucumr.pocoo.org/2022/1/30/unsafe-rust/ https://lucumr.pocoo.org/2022/1/30/unsafe-rust/
- stouset 10mo agoIs three random people saying unsafe Rust is hard supposed to make us forget about C’s legendary problems with UB, nil pointers, memory management bugs, and staggering number of CVEs? You have zero sense of perspective. Even if we accept the premise that unsafe Rust is harder than C (which frankly is ludicrous on the face of it) we’re talking about a tiny fraction of the overall code of Rust programs in the wild. You have to pay careful attention to C’s issues virtually every single line of code. With all due respect this may be the singular dumbest argument I’ve ever had the displeasure of participating in on Hacker News.
- aw1621107 10mo ago> Even if we accept the premise that unsafe Rust is harder than C (which frankly is ludicrous on the face of it) I think there's a very strong dependence on exactly what kind of unsafe code you're dealing with. On one hand, you can have relatively straightforwards stuff like get_unsafe or calling into simpler FFI functions. On the other hand, you have stuff like exposing a safe, ergonomic, and sound APIs for self-referential structures, which is definitely an area of active experimentation. Of course, in this context all that is basically a nitpick; nothing about your comment hinges on the parenthetical.
- disappoint 10mo ago[flagged]
- disappoint 10mo ago[flagged]
- aw1621107 10mo ago> Shold one compare Rust with C or Rust with C++? Well, you're the one asking for a comparison with C, and this subthread is generally comparing against C, so you tell us. > Modern C++ provides a lot of features that makes this topic easier, also when programs scale up in size, similar to Rust. Yet without requirements like no universal aliasing. And that despite all the issues of C++. Well yes, the latter is the tradeoff for the former. Nothing surprising there. Unfortunately even modern C++ doesn't have good solutions for the hardest problems Rust tackles (yet?), but some improvement is certainly more welcome than no improvement. > Which is wrong Is it? Would you be able to show evidence to prove such a claim?
- Dylan16807 10mo agoYou phrase that as if 0-5% of a program being harder to write disqualifies all the benefits of isolating memory safety bugs to that 0-5%. It doesn't.
- disappoint 10mo agoAnd it can easily be more than 5%, since some projects both have lots of large unsafe blocks, and also the presence of an unsafe block can require validation of much more than the block itself. It is terrible of you and overall if my understanding is far better than yours. And even your argument taken at face value is poor, since if it is much harder, and it is some of the most critical code and already-hard code, like some complex algorithm, it could by itself be worse overall. And Rust specifically have developers use unsafe for some algorithm implementations, for flexibility and performance.
- aw1621107 10mo ago> since if it is much harder, and it is some of the most critical code and already-hard code, like some complex algorithm, it could by itself be worse overall. (Emphasis added) But is it worse overall? It's easy to speculate that some hypothetical scenario could be true. Of course, such speculation on its own provides no reason for anyone to believe it is true. Are you able to provide evidence to back up your speculation?
- steveklabnik 10mo agoEven embedded kernels can and regularly do have < 5% unsafe code.
- elsjaako 10mo agoThe first two is the same article, but they point out that certain structures can be very hard to write in rust, with linked lists being a famous example. The point stands, but I would say the tradeoff is worth it (the author also mentions at the end that they still think rust is great). The third link is absolutely nuts. Why would you want to initialize a struct like that in Rust? It's like saying a functional programming language is hard because you can't do goto. The author sets themselves a challenge to do something that absolutely goes against how rust works, and then complains how hard it is. If you want to do it to interface with non-rust code, writing a C-style string to some memory is easier.