4 ms·
> 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 tha
by 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.