News for hackers. Stuff that matters.
Re:The struggle with Rust by rbehrends on Tuesday January 24, 2017 @10:37AM (#13472162)
> First, the expressiveness is all there. You just need to explicitly say you are responsible by using unsafe blocks. So risky pointer and allocation logic becomes the programmer's job, not the borrow checker.

No, unsafe would be overkill and if you needed unsafe, it would put Rust at a massive disadvantage vis-à-vis garbage-collected languages.

Simply put, Rust doesn't handle multiple ownership well. It results in syntactic bloat and/or runtime overhead. But multiple ownership occurs naturally in a number of real-world programs.

> Second, this article only considers the costs of a stricter borrow checker, not the benefits.

This is why I very specifically mentioned that it's a tradeoff.

Re:The struggle with Rust by bluejekyll on Tuesday January 24, 2017 @11:24AM (#13472686)
I think you're implication here is that other languages do handle multiple ownership well. What I think you find in Rust, is that the guarantees you need to make when using unsafe in these limited situations, are the exact same guarantees you need to make in a language like C or C++.

Destroying a circular list takes some thought to make sure you don't double free, same as Rust. Rust just makes those sections of code very explicit and calls your attention to it, while in C you may end up with a segfault, or worse a program that only shows odd bugs during runtime. At least Rust is telling you that you need to put some extra thought in this section.

Re:The struggle with Rust by rbehrends on Tuesday January 24, 2017 @12:21PM (#13473355)
Your assumption seems to be that I'm talking about languages with manual memory management. I'm not; I'm talking about garbage-collected languages, where you get memory safety automatically, regardless of ownership rules. In fact, C++ has some of the same problems that Rust has when it comes to multiple ownership.
Re:The struggle with Rust by kaoD on Tuesday January 24, 2017 @12:38PM (#13473525)
Then use https://github.com/Manishearth/rust-gc if you're willing to pay the price of a GC (still experimental). Or better, stick to a GC'ed language.

If you don't need manual memory management, it's obviously going to be a burden. There are still use cases for manual memory management though, and that's where Rust comes in.

Use the right tool for the job.

Re:The struggle with Rust by Manishearth on Tuesday January 24, 2017 @12:56PM (#13473722)
(Please don't use rust-gc, it's more of a proof of concept. I mean, it works, and some folks do use it, but Rc + Weak are probably better options)
Re:The struggle with Rust by rbehrends on Tuesday January 24, 2017 @12:49PM (#13473634)
> If you don't need manual memory management, it's obviously going to be a burden. There are still use cases for manual memory management though, and that's where Rust comes in.

That's exactly the point that I made in my original comment?

Re:The struggle with Rust by kaoD on Tuesday January 24, 2017 @12:57PM (#13473734)
Sorry, HN isn't great at keeping track who's who on a comment tree.
Re:The struggle with Rust by galangalalgol on Wednesday January 25, 2017 @07:10PM (#13487482)
Does GC imply memory safety? Use after free and dangling references probably can't happen, but I have never heard of a GC supplying cross thread memory safety. The borrow checker does.
Re:The struggle with Rust by rbehrends on Thursday January 26, 2017 @01:14PM (#13493727)
Memory safety in multi-threaded programs is not a hard problem once you have GC. Eiffel solved it decades ago. The JVM also has a weak form of memory safety; it does not preclude data races, but the VM cannot crash as the result of a data race.
Re:The struggle with Rust by humanrebar on Tuesday January 24, 2017 @10:54AM (#13472326)
> No, unsafe would be overkill

I don't see an issue with 'unsafe' if it's an implementation detail and well-tested. Obviously it would be better to avoid it if possible. 'unsafe' is overkill sometimes and worth it other times.

Re:The struggle with Rust by bluejekyll on Tuesday January 24, 2017 @11:18AM (#13472601)
Instead of unsafe, as much as possible should be looking at interior mutability, Cell and RefCell allow for this, with no unsafe, and they guarantee for you at runtime that what you believe is accurate.

unsafe should be IMO, reserved for only those cases where strictly needed, e.g. FFI is the clearest example.

Re:The struggle with Rust by braveo on Tuesday January 24, 2017 @11:19AM (#13472606)
> if it's an implementation detail and well-tested

The same can be said of C and C++, at which point, why does it matter if you use Rust?

Re:The struggle with Rust by humanrebar on Tuesday January 24, 2017 @02:40PM (#13474745)
Rust has opt-out safety with 'unsafe' blocks. C++ doesn't even have opt-in safety. You can get fairly close with smart pointers and some other techniques, but 'fairly close' doesn't cut it when you're talking about memory corruption issues.
Re:The struggle with Rust by AstralStorm on Tuesday January 24, 2017 @03:24PM (#13475111)
You can enforce safety by using the strict type system combined with polymorphic memory allocators in C++17, and get quite close to that with C++11.

The only thing you cannot exactly prevent is "cast_dammit_cast".

Re:The struggle with Rust by dbaupp on Tuesday January 24, 2017 @03:39PM (#13475249)
Could you be specific about how the type system and polymorphic memory allocators defend against things like dangling references, iterator invalidation and use-after-free/move? I can't imagine an allocator affecting these unless it's one that just has a no-op free (which only use-after-free, anyway), nor is the type system strong enough by itself.
Re:The struggle with Rust by AstralStorm on Wednesday January 25, 2017 @02:45AM (#13479543)
1) If you cannot get a plain reference you cannot get dangling references. 2) Use data structures that keep iterators valid and modern reference counted internals. (so that when you have an iterator, you have the object) Alternatively copy on write semantics. 3) Use after move is relatively tricky if you want more. However, your allocator or data structure can catch it with specific implementation of move operators. Use after free can be reduced to use after move or caught with right delete/new operators. 4) Instead, you may have an API where you have your own high level reference-like type. There is a cost to it, same as in Rust. 5) What you cannot do is enforce people to use it always.
Re:The struggle with Rust by dbaupp on Wednesday January 25, 2017 @02:22PM (#13484976)
> There is a cost to it, same as in Rust

All of these things have a larger cost than Rust: you're forced to use pervasive reference counting and very defensive data structures. Rust allows you to get away with pointers deep into other things, as well as aggressive data structures, all in safe code.

Rust also has reliable use-after-move defense for arbitrary resources (not just vague dynamic protections for only the memory resource), and defends against data races. That is, Rust has true safety in a way that can give higher performance than approximate safety in C++.

Re:The struggle with Rust by pjmlp on Tuesday January 24, 2017 @11:31PM (#13478538)
Kind of, you cannot enforce your team mates, consultants and third party libraries that are part of the whole product to use them.

Static analysers and code reviews are not always possible, depending on the target OS and compiler being used, or how the whole project across teams is organized.