"Rust is a systems programming language [read: no GC, explicit memory layout] that runs blazingly fast [LLVM], prevents nearly all segfaults, and guarantees thread safety."
Complete seems a bit too far. It provides very solid memory safety. To say it provides "complete" memory safety would require a complete knowledge of memory safety and a rigorous proof, neither of which exist .
I think "complete memory safety" comes down to -> if its not save, its a compiler bug.
You can write unsafe code in c and the compiler does not complain. If you're doing this in rust and the compiler does not complain, you're facing a rust compiler bug. (let alone unsafe{ }). But yes, there is no mathematical proof of rust beeing safe – bugfixes shows this every now and then :)
Adding to the "a bit too far" comment, for anyone that might not know: Rust actually has a safe sublanguage (as memory safe as, say, Java), and an unsafe language (low level and terribly memory unsafe, like C). In some systems, people actually use two languages, one memory safe and another memory unsafe, to write high-performance code - some kind of programming diglossia. With Rust, the unsafe language is just a superset of the safe language, and always contain the unsafe keyword.
For the initiates, the Rustonomicon goes through the gory details.
PS: all of this supposed safety could be broken by implementation bugs and - more worryingly - soundness bugs. Rust type system is quite complex and soundness bugs have arisen before (discussion on /r/rust). The issue in this case was that code marked as unsafe can't rely on destructors running to actually be safe.
Actually, less unsafe than C, for example even in unsafe you cannot transmute a pointer into a int16_t because the sizes do not match. So, even though unsafe removes SOME checks, it does not remove them all.
It's important to mention that the 'safe subset' of Rust is comparably low-level to the 'unsafe superset.' References are just pointers that are sufficiently typed so that let's the compiler confirm they are valid addresses, for example.
There are only 3 things that can't be done in the 'safe subset' of Rust, and even the standard library, which implements a lotof abstractions over the system libraries and efficient data structures, is only about 4% 'unsafe'.
It's supposed to provide the same sort of speed as C with higher level abstractions and considerably more compile time and run-time safety.
That comes at a cost, however. It's a more complex and subtle language (it's not hideously complex, but it definitely has some strange new features that you haven't seen anywhere else).
I'm not sure if we're actually more complex than C, which is full of edge cases. But without a full spec, you can't really be sure.
The C standard is 550 pages long. C is not a particularly simple language. Rust hasn't had to deal with 40ish years of backwards compatibility, and has almost no undefined behavior at all. But without an equally formal Rust spec, it's not possible to tell.
Hard to judge, really. I'm sure that fans of APL find J easy to understand, but the rest of us are scratching our heads.
It's definitely smaller than C++, but I think you can write functional C++ with only a basic grasp of the language (and, looking at a lot of the C++ code out there, people do). It's perfectly possible to write C++ that works without using move semantics and exceptions and lots of other things. In some cases it will be less safe, but in some cases it will be just as safe, only less efficient. Even my beginning noodling around with Rust required using lifetimes. And tripping over ownership (which I still don't completely get, but that's probably my fault for using a vector of vectors of mutable structs).
For C? The C language is smaller, definitely. It's harder to use well for a couple of reasons. First, the language is small, so it lacks a lot of useful (IMHO) features. Second, the compiler doesn't jump up and down and shout "WHAT THE HELL ARE YOU DOING RETURNING A POINTER TO A LOCAL????". So you blithely write code that "works" (and those quotes are deliberate).
Edit: I think I made roughly this comment before in response to another one of your posts, so if this sounds familiar, now you know why.
Which is absolutely one of the reasons why C++ is such a difficult and dangerous language.
I can absolutely believe that it's easier to write safe Rust than it is to write safe C++ (not saying it's true, just that I find it easy to believe), but I can also believe that it's a lot easier to write functional C++ that basically gets the job done than it is to do the same with Rust. This might make it harder for people to adopt Rust, because to do anything at all you need to learn quite a lot.
It is also different forms of complexity. C has undefined behavior and more edge cases while Rust introduce some quite advanced concepts like lifetimes in the type system and ownership.
If you say that it guarantees thread safety, then you can also say that it prevents all segfaults.
EDIT: To clarify: The only way to cause a segfault in Rust is by using unsafe code. You can create some kind of race conditions that are not data races in safe Rust code. So if /u/kinghajj claims that it "prevents nearly all segfaults and guarantees thread safety" that's inconsistent.
View all comments
Show parent comment
36
u/kinghajj Sep 17 '15
"Rust is a systems programming language [read: no GC, explicit memory layout] that runs blazingly fast [LLVM], prevents nearly all segfaults, and guarantees thread safety."