3 ms·
There's a solid argument that memory-managed languages like Java are safer than Rust, because although your program can crash, it can't segfault unless you're d
by armchairhacker 3y ago
There's a solid argument that memory-managed languages like Java are safer than Rust, because although your program can crash, it can't segfault unless you're doing something especially weird. Safe Rust programs can also crash via `panic!`, and unsafe Rust programs can segfault and create wonky UB just like C programs if the safety invariants aren't manually enforced.
The safest language would be something like Elm or Datalog, where the type system ensures crashes aren't even possible. But then you just make up your own idea of failure, where instead of crashing the program produces unexpected output, almost like UB.
- dezgeg 3y agoCan't you segfault in Java via stuff in sun.misc.Unsafe?
- pornel 3y agoRust's panic is technically very similar to a Java exception. It does not lead to any unsafety. It throws before executing anything that would be unsafe. Safe Rust can't segfault, unless you're using unsafe code that is buggy, which isn't that much different from using buggy JNI. Beyond just memory safety, Rust has a stronger type system than Java — tracks mutability, ownership, and thread safety that Java doesn't.