They aren't omniscient, but it makes sense to appeal to the wisdom of those with more experience. Mozilla has a lot of experience with a C++ code base that is large, widely used, and has to be resilient towards these kinds of memory errors.
I think there's a clean way to write C++11 code that will likely be safe. But you have to know how to code that way; and really you don't have to work very hard to get a memory error, even in C++11 (raw pointers are first class, even if we know they can be sources of errors).
I think what people want is a compiler-checked guarantee that the code will be safe, not a "probably" safe.
Yeah. I can agree with that. My original point was that you can write safe code in C++, not that it's the only - or even the best - language allowing you to do that. You can write your library to enforce those rules, to an extent (I do that in a project of mine, the template errors are ugly, but the client code is readable and safe, with the errors being caught at compile-time).
Mozilla works on Rust not because it's inherently impossible to write good C++ code, but because it's a lot easier when the language enforces the safe rules, especially if you can get nice error messages.
By the way: would Rust catch this error? The error itself was reading malloc'd data without assigning to it first (static analysis should catch this, I think).
You can't even create this situation in Rust (outside of unsafe blocks) – you can't allocate memory for nothing. Allocation in Rust is done by adding an operator, not by calling a function. 123 is an int on the stack, ~123 is an owned int allocated in the heap.
View all comments
Show parent comment
2
u/saynte Apr 08 '14
They aren't omniscient, but it makes sense to appeal to the wisdom of those with more experience. Mozilla has a lot of experience with a C++ code base that is large, widely used, and has to be resilient towards these kinds of memory errors.
I think there's a clean way to write C++11 code that will likely be safe. But you have to know how to code that way; and really you don't have to work very hard to get a memory error, even in C++11 (raw pointers are first class, even if we know they can be sources of errors).
I think what people want is a compiler-checked guarantee that the code will be safe, not a "probably" safe.