Those times when C compilers did obvious translation to machine code are long gone. Now compilers are super-smart and can inline functions, throw away code _they_ think is not needed, replace loops with vector instructions and list goes on. It's really hard to tell what's happening at a low level for a given C code.
The unsafe code is neatly delimited, so you can write 95% of your application in safe code, and the remaining 5% in unsafe code and offer a safe interface to the programmer. This is the real strength of Rust IMO, you don't need to be hyper alert in every single function you write.
> at which point you're as vulnerable to programming mistakes as C.
Yes, but if you start off in C's typical domain, then you cannot decompose your problem set into safe and unsafe bins using C. So you're stuck with unsafe-lowest-common-denominator everywhere you go.
Re:Death to C
by sharpercoder on Saturday May 02, 2015 @10:12AM
(#9477102)
This is okay. The point is that the majority of time, compiler checks/errors warn you from mistakes in safe code blocks. As such, you can put more focus on the actual unsafe parts.
It is not about completely removing unsafe stuff. It is about reducing the possible mistakes as much as possible.
I agree. One of the best parts of C is how simple it is.
Not necessarily as the idea is to isolate those components into the unsafe blocks, and having locality on a bug is a pretty big component of fixing it.
Well, that's locality on what in theory could be causing a bug, but not on where it might manifest, i.e. a wild pointer trashing data maintained by purely safe code.
Still, in theory isolating the possible causes is a fantastic advantage.
Even if you did decide to use Rust instead of C in C's typical domain - operating systems, drivers, and constrained resource devices - you would be forced into using "unsafe" blocks anytime you had to interact directly with the hardware, manually manage memory, or issue ASM commands; at which point you're as vulnerable to programming mistakes as C.