77
creeebz
8y

So sick of my colleague who keeps writing:
if (something) {
doWork();
} else {
}

He insists that it is the best code style to include the empty else clause. WRONG YOU #!*&@!

Comments
  • 14
    If you are getting paid by line of code then it is :D
  • 0
    I personally prefer

    If(something)
    Dowork();

    If there are no use of else. Some of my coDevelopers do not like it. But who care.
  • 1
    I learnt that the else part is redundant if you are returning something in the if statement.
  • 1
    @abcdev your coDevelopers care ¯\_(ツ)_/¯
  • 1
    @kshitij got to love defensive programming
  • 4
    Wtf seriously?? It would make.me think 'uh oh someone forgot something here' or 'hmmm looks like this code is not finished yet'. So, your colleague is an asshole and he really should stop doing that. It sucks. Big time.
  • 0
    @CodeMasterAlex true that. It's actually look like incomplete.
  • 0
    I've heard of companies requiring this as once a serious bug happened because something wasn't in an else, I actually don't think it's bad practice to write this necessarily.

    It doesn't bog down your runtime and really isn't all that confusing, and has a chance to stop or catch bugs
  • 1
    @tylerhartwig If something wasn't in an else it is a logic error. You should never write empty statements, it's confusing for others, makes you write more code that isn't used and really does not aid to higher code quality but lower instead.
  • 0
    Empty else brackets are not wrong. There are plenty of books talking about this topic (my favorite one is "code complete").

    About the fact that it is confusing, well... You can simply leave a comment there:
    // This is here for blah blah blah and for now there is no use for it

    All of the above, IMHO :)

    Saludos!
  • 1
    @javierojeda also if it's a standard in a work place.. It can be communicated once, at the first code review of a new person
  • 4
    @creeebz , send him/her a note saying.

    You better stop with the fucking empty clause elses. Or else{}

    😂😂😂
  • 2
    @abcdev I prefer
    if(something) doWork();

    If the method is short named
  • 0
    I prefer

    doWork() if (something)
Add Comment