And what happens when you don't check? It crashes. That's the unsafe part.
These crashes are simply not possible in Rust and Haskell, and the type system notifies you if failure is possible (because the function will return an Option/Maybe).
And what happens when you don't check? It crashes. That's the unsafe part.
These crashes are simply not possible in Rust and Haskell, and the type system notifies you if failure is possible (because the function will return an Option/Maybe).
You can easily generate a segfault in Rust in 'unsafe' (or 'trusted') code; that might only restrict errors of that nature to code that uses unsafe blocks.
Practically speaking that's pretty common; once you enter an FFI unsafe block, you lose all type safety; but you can totally do it without FFI too. Eg. using transmute().
In fact, there's no way to know if you code contains 'hidden' unsafe blocks wrapped in a safe api in some 3rd party library that might cause a mysterious segfault later on.
You can argue that 'if you break the type system you can do anything, obviously'; that's totally true.
I'm just pointing out the statement: "These crashes are simply not possible in Rust and Haskell" <-- Is categorically false.
You can chop your own arms off in Rust just like anything else (including Go).
Not directly addressing what you're saying, but, IME people are far too quick to use `unsafe` code. One needs to be quite careful about it as there's a pile of invariants that need to be upheld: http://doc.rust-lang.org/master/rust.html#behavior-considere...
> once you enter an FFI unsafe block, you lose all type safety
You don't lose all type safety, especially not if the FFI bindings you're using are written idiomatically (using the mut/const raw pointers correctly; wrapper structs for each C type, rather than just using *c_void, etc).
http://blog.llvm.org/2011/05/what-every-c-programmer-should-...
First, mapping that page doesn't cause all null pointer dereferences to segfault.
And second, the language doesn't require a segfault. In fact, it explicitly permits the implementation to do whatever it likes.
That is the difference between safe and unsafe. It is in the language definition.
C doesn't define behaviour of a null deref, but most compilers map a -rwx page there to ensure that attempts to deref fault.
In what circumstance do they not?
http://blog.llvm.org/2011/05/what-every-c-programmer-should-...
Considering that "safe" removes most of the usefulness of the word "safe".
I agree it's better to avoid null dereference errors by not putting null in your language, but by the normal meaning of safe here, go is safe.
Also, I wasn't making a point about the word "safe". I was making a point that if go is "safe", then the word "safe" is useless.
There is a problem here. Don't want to call it "unsafe"? Ok. Call it crashy, instead.