The difference here is between one return point and multiple return points.
Typically, a code with a single point of return tends to do a lot of bookkeeping (temporary variables, check these variables in loops) and can get hairy as the logic becomes more complex. I saw code that goes to great lengths to use the while (flag) ... flag = false; pattern while (flag) ... flag = false; instead of the while (true) ... break; pattern while (true) ... break; and it’s not interesting to read.
I prefer several return points, as they return as early as possible (no extra work is done) and do not require local residents to help keep track of the current return value. Also, I don't find them harder to read than code with a single return point.
There's a nice divergence of this on c2 ( SingleFunctionExitPoint ).
I found that keeping the methods as "functional" as possible is good (I say "functional" here because I usually do C #, which outside LINQ is not considered functional). By “functional,” I mean that I try to avoid the mutating state as much as possible. Introducing more states in the form of local residents or members makes it difficult to understand, since now you have to consider their values, and you have to consider how these variables can be set (from another method, from another class, ...).
In general, a state is evil, but sometimes it is a necessary evil.
There is an interesting conversation about this particular issue here on SO .
source share