|
|
|
|
|
by synthc
1339 days ago
|
|
Yes this is exactly what I meant.
After years of coding in Haskell and Clojure, and then going back to Java I have absolutely no problems with int max(int x,int y) {
if (x>y)
return x;
else
return y;
}
I just looks completely fine to me, but colleagues would complain about it in reviews and I just don't understant the problem at all.
The variant with the extra result variable looks just wierd to me, and I have seen much uglier code written by people desperately avoiding early/multiple returns. |
|
In imperative programming, a bunch of nested conditionals can easily have incomplete coverage of possible program states, and it can be easy to overlook problems if you have a mixture of side-effect branches and early returns. I think some people struggle with this more than others, and it can flummox them almost like goto-laden spaghetti code.
Of course, there are other areas where similar errors can occur in different languages, i.e. in exception-handling or pattern-matching constructs. There are many different coding styles which can make these control-flow structures easier or harder to debug. But, I think there can also be a lot of "cargo culting" where zombie rules of thumb continue beyond when they were really particularly helpful.