3 ms·
> It is absolutely infuriating as a programmer to call a function and not know if it can throw and, if it can, not know what it can throw. It’s a disaster. Eve
by marshray 3y ago
> It is absolutely infuriating as a programmer to call a function and not know if it can throw and, if it can, not know what it can throw. It’s a disaster.
Every nontrivial function can fail (in C even a unary operation on an int), it's just a question of whether and how the caller is informed, how easily the failure is to ignore and continue processing in an undefined corrupted state, and what percentage of the code ends up being dead branches for impossible-but-unprovable error paths.
> I so desperately wish that C++ had Rust’s Result type and pattern matching.
I'm a fan of Rust too, but what do you think panic() is?
Rust has no concept of code that always succeeds. It's all-but impossible on current CPUs.
https://github.com/search?q=repo%3Arust-lang%2Frust+path%3A%2F%5Ecompiler%5C%2F%2F+%22.unwrap%28%22&type=code https://github.com/search?q=repo%3Arust-lang%2Frust+path%3A%...
https://doc.rust-lang.org/std/result/enum.Result.html#method.unwrap https://doc.rust-lang.org/std/result/enum.Result.html#method...