Earlier quoted context omitted.
> As someone who's not a day-to-day developer/software engineer: the Go code is more readable. COBOL is what you get when you optimize for readability by people who don't know how to program. > The Rust is interesting, for sure, but I don't know what "?" is doing. I like the use of the question mark as it makes the act of calling the function a question - did it work or not? But what's not obvious is what happens if…
> It gets returned to the next level up, exactly like in the analogous Go code above. That sounds utterly horrible. You would never actually write that Go code in the real world. Let's modify the original example slightly: res1, err1 = canFailA() if err1 != nil { return err1 } res2, err2 = canFailB() if err2 != nil { return err2 } Let's assume an error was returned. You realize from the error that there is a bug in t…
This is why the popular approach in Rust is to add "failed to do X" to the error before returning it, which is handled by popular libraries.
An example of the effect:
Failed to start, caused by
Failed to load config, caused by
File not found (the error from the OS)
> This is a real problem that should be solved, but it's not a problem of errors. It's a problem of values in general. Remember, the Go language has no inherit concept of error. Anything that we happen to call an error is actually just a user-defined type, same as any other type a user might define (birthdate, order number, stock price, etc.).
The concept that a function can fail is pretty fundamental, ignoring it at the language level is like saying "a function failing is not common enough to address consistently"