points by K0nserv 2 days ago | 0 comments
> There's no protection for not checking return values, and it's probably not even possible to protect against (in entirety)
That's exactly what you get with Result and Option, it's impossible to forget.
Compare:
char* hash = crypt(key, salt);
// We crash here on the hash derefence, it's no clear from the code
// that we were supposed to check for NULL or that we forgot.
if (!strcmp(hash, expected)) {
}
To: let result: Result<Vec<u8>, Error> = crypt(key, salt);
// We MUST write this line, which is a very clear signal
// that we can panic here.
// This can be grepped for or forbidden.
let hash: String = result.unwrap();
// if result == expected { would type error
if hash == expected {
}
[–] pheggs 2 days ago
[–] K0nserv 2 days ago
[–] pheggs 2 days ago
[–] slopinthebag 2 days ago
[–] pheggs 2 days ago
[–] orf 2 days ago
You are really uninformed: different programming languages have very different volumes of bugs per line of code
[–] pheggs 2 days ago
[–] K0nserv 2 days ago