I am trying to reorganize some code and make it easier to read. I noticed that I have some unnecessary return statements at the end of some functions. Here is a conceptual example:
func someFunction(a []arr) int {
for _,v := range a {
if v == something {
return somethingElse
}
}
return -1
}
In my opinion, the return statement at the end of a function is misleading, since it assumes that it can be reached at some point. How can I prevent this?
Please note that I'm doing error handling in some other place, so I can be sure that someFunctionit will always return somethingElse.
source
share