|
|
|
|
|
by kirici
336 days ago
|
|
>With Go's multiple return values to represent errors, they are also known to be too easy to "forget" to even look at the error value. How?
Unassigned foo := myFunc() # [...] assignment mismatch: 1 variable but myFunc returns 2 values
Assigned, but not used foo, bar := myFunc()
fmt.Println(foo) # [...] declared and not used: bar
Intentionally ignored foo, _ := myFunc()
Ignoring is a deliberate decision and trivial to review, lint and grep for.Except for, I suppose, shadowing a variable before checking it foo, bar := myFunc()
_, bar = myFunc()
fmt.Println(foo, bar)
Which is more of a general grievance of quite some people, but I don't think that has much to do with multiple returns - and you definitely have to look at the error to pave over it afterwards.edit: https://goplay.tools/snippet/E69xFuIcG7I |
|