3 ms·
I would be very interested in how these two languages enable safe data structuring. Do they have significant tradeoffs in terms of ergonomics, control, or perf?
by Gankro 10y ago
I would be very interested in how these two languages enable safe data structuring. Do they have significant tradeoffs in terms of ergonomics, control, or perf?
Keep in mind basically all of Rust's libcollections uses unsafe code for perf and low-level representation reasons. They can all be made safe using the strategies every other safe language uses (and eating the associated downsides).
Also keep in mind Rust's data structures are basically language primitives in a lot of other languages!
- pjmlp 10y agoModula-3 has GC. You can only make use of untraced pointers in unsafe modules. So unless proven otherwise by the profiler, no need to make use of unsafe code. Ada requires explicit use of unsafe code for memory deallocation, but it is not required when using RAII pools. So unless a custom allocator is required, the standard pools can be used. In Rust even a basic double linked list requires unsafe. Then there are those that make use of unsafe to try to express code that cannot be proven by the type system, instead of plain memory corruption issues. Thankfully the core team is against this trend.
- tatterdemalion 10y ago> In Rust even a basic double linked list requires unsafe. Well this just isn't true. You can write a doubly linked list using Rc and Weak pointers and no unsafe code. This is the same as saying you can write a doubly linked list using GC'd pointers.
- geofft 10y agoI didn't see this comment when replying above, but you can write a doubly-linked list in safe Rust with either of these approaches (GC, or stuffing everything into a single giant reference). The only reason a "basic" doubly-linked list in Rust is unsafe is that those aren't really reasonable options, and Rust wants to do better. I don't think it would improve Rust to give it mandatory GC (Go and Java are both great languages if you want that), or to require that all allocations are unsafe unless you use memory pools.
- pcwalton 10y ago> Modula-3 has GC. You can only make use of untraced pointers in unsafe modules. > So unless proven otherwise by the profiler, no need to make use of unsafe code. > Ada requires explicit use of unsafe code for memory deallocation, but it is not required when using RAII pools. So, if you want to write hash tables like this without unsafe code, you're in luck: Rust lets you do it! (As an aside, I keep seeing these fantastical claims about Ada that, when you dig into them, come with the exact same or more restrictive semantics than Rust. Ada is a good language, but it isn't magical, and the region/lifetime/uniqueness systems in Rust actually solve real problems that Ada doesn't have a solution to.)
- nickpsecurity 10y ago"As an aside, I keep seeing these fantastical claims about Ada that, when you dig into them, come with the exact same or more restrictive semantics than Rust." Ive been looking forward to seeing such a point-by-point comparison of safety features between Rust, Ada, and SPARK. I gave you or someone else involved in Rust the Safe and Secure Ada 2012 book listing those features to help. Just link to it in a reply to me if and when you publish such analyses. Btw, even if I agree on restrictive semantics, the thing you didnt mention is results where Ada and esp SPARK are immune by default to so many error classes. Rust definitely had it beat on dynamic safety and probably concurrency. However, unsafe programming in SPARK is still quite safer than Rust. :)