This is the reverse of the issue that the parent mentioned though!
Consider a go function foo which returns some value and an error. What can you do with that error? You mention control flow being broken by python and others, but the control flow of
def myfunc():
if foo():
do_a()
else:
do_b()
and
def myfunc():
try:
cond = foo()
except:
raise
if cond:
do_a()
else:
do_b()
and
func myfunc() err {
cond, err := foo()
if err != nil {
return err
}
if cond {
do_a()
} else {
do_b()
}
Are all the same! And you can't do anything different in them, because in go, you have no knowledge about the error. Is it aa temp error you should retry? Who knows, are you going to parse the error string to figure it out? The
only think you can do in go to an error from some library function is pass the error, possibly adding some additional context, because otherwise you may be mishandling the error.
In exception based languages the "pass the error" case is done for you, but if you do want to retry retriable errors, you can actually use a language feature to know that. In go, you have to hope the library creator created an interface (and that all of the possible errors that could percolate up have compatible error-extension interfaces!) that includes some kind of type information, which almost no one does.
You're talking about "sensible" control flow, but go doesn't have it!