4 ms·
> safer software What makes Rust-written software safer?
by jbkkd 12y ago
> safer software
What makes Rust-written software safer?
- shadowmint 12y agoThis has been covered repeatedly in the past. Rust inherently helps to prevent many types of memory related and concurrency errors. Rust programs are not 'safe' in the sense that they cannot crash or have security bugs, but they are 'safer' in that the compiler automatically performs a series of safety checks to prevent common errors.
- MichaelGG 12y agoAnd note that the most serious security bugs in widespread software[1] are typically exactly these common errors. Eliminating them would have prevented nearly all of the remote execution bugs in history. 1: Widespread meaning OSes and popular platforms, not custom LOB apps where SQL injection exists on the login page.
- dscrd 12y agoOption types and safe pointers, and modern abstractions. Some other programming languages offer these too, but Rust attempts to do them while incurring no run-time costs.
- wyager 12y agoIt is effectively impossible to have an unsafe memory access error in Rust. The compiler eliminates a huge variety of bug types, including null pointer dereferences, use-after-free bugs, memory leaks, etc. All arrays are bounds-checked and rust encourages good programming practice like using abstracted list-processing mechanisms (like mapping instead of loops) and algebraic types instead of e.g. null pointers.
- shadowmint 12y agoIt is effectively impossible to have an unsafe memory access error in Rust Please, don't say that. Lets be reasonable. Rust is great, but Rust code crashes and segfaults too, just like any language, programs have bugs, and those bugs can cause program failure. Rust just has less of them, because it has a smart compiler. ...but it's not right to suggest that it has none. Remember: There is no way of ensuring that a rust program does not result in a segmentation fault or other memory or race condition as a result of unsafe code. There is no way of ensuring a rust program does not contain any unsafe code.
- Dylan16807 12y agoI don't understand your post. If you mean 'unsafe' as in 'may misbehave' then the compiler can definitely ensure there will be no segmentation faults and there cannot be certain classes of race condition. If you mean 'unsafe' as in the keyword that lets you do dangerous things, it's trivial to check if your source has blocks marked with that keyword. There's no way to ensure the compiler is perfect, but rust itself is not capable of certain types of errors. You can always code the wrong algorithm, but that doesn't mean you can segfault or use after free (in the default safe mode you almost never have an excuse to leave).
- shadowmint 12y agoThis is a misconception. You are flat put wrong, and spreading misinformation about it doesnt help anyone. If you use any rust, and that includes dependencies and the standard library with unsafe code, bugs in the unsafe code can and do cause segmentation faults. Its easy to say, 'well, thats a bug in the library, not a problem with rust', but thats the same as with C++ isnt it? If you can assert any code is 100% bug free then why do we care about the nice safety features in rust? What is true is that any 'safe' code path that never enters an unsafe block in rust proveably cannot result in certain types of failures. BUT every rust program uses unsafe code. In the standard library. In c bindings. In 'safe' pure rust dependencies (with hidden unsafe blocks). In loading dynamic libraries. Its completely unavoidable. What are going to do? Vet every line of every part of every dependency in the code you use? Dont be ridiculous. Do you use rust? ..because practically speaking it does crash. Not often, sure. ...but this falacy that rust is 'provably safe' is absolutely false. Its provably false. Thats why people saying it is unfortunate; it makes the rust community look like a bunch of clueless fanboys. Please stick to reality. Rust has a zero cost memory management strategy and a smart compiler that helps to prevent certain types of common errors. We dont need to step into magical fairy land to convince people rust is good. It stands on its own merit easily enough.
- Jweb_Guru 12y agoHow often has one of your Rust programs segfaulted for you, when it wasn't a bug in your own unsafe code (as opposed to that in the standard library)? For me, the count still stands at zero. I've been writing Rust for well over a year. I like to abuse new features and I've found many compiler bugs, but my code doesn't crash at runtime. I'm not saying it doesn't happen, and the plural of anecdote is not data, but I think you're grossly misrepresenting Rust's practical safety benefits. That you only have to trust code in unsafe blocks, rather than all the code everywhere, is a huge benefit.