Having an Early return from void methods

I was having a debate of whether it is ok to have return in a void method.
I always do it and have the guard clauses at the beginging.

But my colleagues sees it as bad practice to have return in a void method.

THis is s really good link

https://stackoverflow.com/questions/1283325/is-it-bad-practice-to-use-return-inside-a-void-method

A return in a void method is not bad, is a common practice to invert if statements to reduce nesting.
And having less nesting on your methods improves code readability and maintainability.
Actually if you have a void method without any return statement, the compiler will always generate a ret instruction at the end of it.

Leave a comment