|
|
|
|
|
by dmantis
26 days ago
|
|
Wouldn't Rust's Result or Go's error checking prevent that? While not mandatory, a person would probably use it instead of the * hack. Simply because the calling side wouldn't have an option to forget the check like with the NULL case |
|
- result.unwrap() will panic if it failed
- result.ok() throws away the error but gives you a None value instead (still can’t use it as if it’s a success)
- matching on the Ok variant and doing nothing on the Err variant, you only get to use the success value inside the Ok arm
Etc etc.
The problem is when the compiler says “NULL is a valid instance of T”, which go lets you do, and rust doesn’t (without using the unsafe keyword and intentionally casting a null pointer, which you don’t do by accident.) Go lets you write code like `var hash string; hash, _ = hashfn()` and it compiles and now you have null instead of a valid hash.