12

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.

Comments
  • 4
    No. If it's not necessary, it's useless code. It serves no purpose.
  • 3
    @Trey50Daniel That's what I told him
  • 5
    @lovengore Yeah obviously he's an idiot that writes spaghetti code.
  • 2
    Oh mate, maybe he is kidding you
  • 3
    Else:
    Print(should never happen)

    ;)
  • 1
    @qwerty1337 that is not true. We don't know whether there's somth after that if
  • 0
    I 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.
  • 5
    Actually... 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. :)
  • 0
  • 0
    @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.
  • 0
    @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. :)
  • 0
    @arekxv Yeah well code analysis tools like Sonarqube would disagree with that ;) But I guess it's also a bit of personal preference.
  • 1
    @lig1 yeah you are correct

    Should have been

    // Do nothing

    Instead of print :)
  • 1
    @qwerty1337 you cannot just put comment on a block in Python
    It could look like

    # do nothing
    pass
Add Comment