Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
lig114458yI believe that reviewer should read about control flow branches and you should write some tests which shows that you know how program will work in case that virtual else branch is active.
-
arekxv10528yActually... from a clean code perspective you should strive to NEVER use else in if statements. Sure, it cannot be avoided sometimes but if you look closely about 80% of else statements can be removed entirely if you restructure your code and exit the function early. :)
-
@arekxv Depends on what you call clean code. It's actually a fairly common good practice to only have 1 return statement in a function.
-
arekxv10528y@LucaScorpion
Actually one return statement practice is bad IMO, because it promotes if-else practice. There is nothing wrong with many return statements in one function, as long as you keep the function below 20-30 lines which should be easy when you remove else clauses. :) -
@arekxv Yeah well code analysis tools like Sonarqube would disagree with that ;) But I guess it's also a bit of personal preference.
-
lig114458y
Related Rants
So I wrote a python code and was waiting for +1 on code review and I needed to merge it fast. That shit of a reviewer took his time to finally NOT give a +1 with comment, "if statement has no else part". OF COURSE IT DOESN'T HAVE ELSE PART. I DON'T NEED A ELSE PART. But to give him the benefit of doubt, I'd like to ask devRant community if they believe all ifs should have elses.
undefined
gerrit
else
if
python
git
review
frustrated
wtf