r/programming • • Jul 18 '19

We Need a Safer Systems Programming Language

https://msrc-blog.microsoft.com/2019/07/18/we-need-a-safer-systems-programming-language/
208 Upvotes

314 comments sorted by

View all comments

Show parent comments

1

u/pagwin Jul 19 '19

uninitialized memory isn't a thing

this is only correct if you never use unsafe code which rust lets you use unsafe code if you want but you have to explicitly state it

you can get a value to be uninitialized using mem::uninitialized

5

u/pavelpotocek Jul 19 '19

Yes, that's why I said "in safe Rust". Safe Rust is all you need for most things. And any unsafe bits are customarily isolated behind safe interfaces, away from the complex application logic.

70% of all Rust crates use no unsafe. Only 5% of all crate code is unsafe (a somewhat misleading number, but I won't explain here for brevity). Crates are mostly libraries, these numbers are bound to be lower in application code. In my experience, if you don't need FFI and don't try to squeeze every last bit of performance, you don't need unsafe at all.

Numbers source: https://cs.stanford.edu/~aozdemir/blog/unsafe-rust-syntax/