3 ms·
If it denied you efficiency in the name of dogmatic safety, you'd just go back to using C++. For new work, most efforts are going forward to C# or D or Go or J
by Animats 12y ago
If it denied you efficiency in the name of dogmatic safety, you'd just go back to using C++.
For new work, most efforts are going forward to C# or D or Go or Java, all of which solve this problem by using a garbage collector. The claim for Rust is that it's memory-safe without a garbage collector. This claim does not appear to stand scrutiny. If 10% of a browser has to be "unsafe", the language is seriously flawed.
- pcwalton 12y ago> For new work, most efforts are going forward to C# or D or Go or Java, all of which solve this problem by using a garbage collector. The claim for Rust is that it's memory-safe without a garbage collector. In C#, D, Go, and Java, arrays are implemented as language primitives in the runtime. Their runtimes are implemented in raw C or C++ and are not formally verified. So my question is: Why is implementing an array in C as a language primitive safer than implementing it in the standard library via unsafe code? There's a similar story for the swap operation. Rust in fact used to have a swap operation, as you suggested, but it was removed because such an operation can easily be implemented in the library. We could have moved the code back into the compiler, but how would that have made the language safer? (In fact, I would be tempted to argue that implementing language primitives in codegen is less safe, since programmatically generating LLVM IR is more difficult than writing essentially C with a different syntax.)
- tomp 12y agoYou didn't really answer the question. The GP was asking, how can Rust claim to be "memory-safe" if 10% of application code (e.g. Servo) is unsafe code. We can accept unsafe code in the standard libraries (equivalent to how C# or Java or Go are implemented), as it's reasonable to assume it will be extensively peer-reviewed and battle-tested.
- pcwalton 12y agoYou shouldn't be writing unsafe application code. If your applications needs new unsafe abstractions (which you can think of as language extensions), then you can write those. But unsafe is absolutely not for application code. (This is, as I explained downthread, part of the reason why I dislike going around quoting "X% of the code in Y app is unsafe." Your application code shouldn't be unsafe.)
- pjmlp 12y ago> Their runtimes are implemented in raw C or C++ and are not formally verified. This is not true of all implementations. There are meta-circular implementations of Java and C# compilers, that people keep forgetting about.
- Rusky 12y agoRight now, pretty much 100% of all browser code is "unsafe", because they can't (for a pragmatic definition of "can't") be written in C#/Go/Java and have to be written in either C++ (or something equally unsafe), or something else with more static analysis. That's why dogmatically going with safety drives those projects back to C++. The implementations of C#/Go/Java are also 100% unsafe, as they're in the same boat. Getting that 100% down to 10%, where the 10% is clearly marked and sequestered behind safe interfaces that are well-tested and well-audited, is a much better solution than giving up on one or the other of performance or safety entirely.
- pjmlp 12y ago> The implementations of C#/Go/Java are also 100% unsafe, as they're in the same boat. No, because there are(will be in Go's case) meta-circular implementations available. C and C++ aren't the only way to implement compilers.
- Rusky 12y agoThat's the exact principle I'm talking about- meta-circular implementations shrink the amount of unsafe code and confine it to specific places where it can be better tested and checked. Rust's unsafe-with-safe-interfaces style is just another way to do that, which honestly is a lot more straightforward.
- pjmlp 12y agoThat is how meta-circular implementations work anyway. You need to have some intrinsics for the really unsafe parts, or get them in Assembly. Sorry for not getting your point fully.