yegor256 / qulice

Quality Police for Java projects: aggregator of Checkstyle and PMD
https://www.qulice.com
Other
301 stars 111 forks source link

There is no reason for single return #943

Closed golszewski86 closed 5 months ago

golszewski86 commented 5 years ago

There is a rule defined in qulice-checkstyle/src/main/resources/com/qulice/checkstyle/checks.xml file:

<module name="ReturnCount">
   <property name="max" value="1"/>
</module>

This rule however has no real justification. Yes I read the blog post https://www.yegor256.com/2015/08/18/multiple-return-statements-in-oop.html but it's not conclusive. It present the perfect OO approach but then states it's impossible in java because "Java doesn’t have that. Java (and many other pseudo OOP languages) gives us operators" followed by some consideration how the perfect OO language would look like. And the last statement is " let’s stick with just one return".

Why? What's the difference between returning value directly and assigning it to a variable and returning this variable? Those are two very similar ways of writing the same, except the direct return requires less code is more readable.

0crat commented 5 years ago

@krzyk/z please, pay attention to this issue

0crat commented 5 years ago

@golszewski86/z this project will fix the problem faster if you donate a few dollars to it; just click here and pay via Stripe, it's very fast, convenient and appreciated; thanks a lot!

krzyk commented 5 years ago

@golszewski86 this is a question to @yegor256

longtimeago commented 5 years ago

More thoughts about the rule https://softwareengineering.stackexchange.com/questions/118703/where-did-the-notion-of-one-return-only-come-from

yegor256 commented 5 months ago

@golszewski86 definitely, there are arguments in favor of multiple returns, but Qulice is a very opinionated and extreme toolkit. We only believe in what we like, and we strongly disagree with everything else :)