Why Many Return Statements Are a Bad Idea in OOP

Discussions

News: Why Many Return Statements Are a Bad Idea in OOP

  1. The question is whether a method may have multiple return statements or always just one. The answer may surprise you: In a pure object-oriented world, a method must have a single return statement and nothing else. Yes, just areturn statement and that's it. No other operators or statements. Justreturn. All arguments in favor of multiple return statements go against the very idea of object-oriented programming.

    Continue reading...

  2. "Troll marketing", again? Untrue unless proven otherwise. Luckily, Yegor has no authority (moral or otherwise) to tell us what is blessed OOP, even if this article is redacted like he has. Same song again and again: let's show a simple example and conclude you've proven an universal truth. You can't even argue with the guy, because he'll keep on saying it's "logical".

    I do think that multiple return statements in a 100-lines (!) method is bad. But I also think that some simple exiting shortcuts at the very beginning can be a good thing, sometimes.