60
myles91
7y

if (someCondition) {
doSomething();
} else {
// THIS SHOULD NEVER HAPPEN
}

Saw this in our repo the other day, face palmed so hard that my face is now a palm.

Comments
  • 1
    I've seen that snippet of code somewhere before... Oh that's right. EVERYWHERE.
  • 1
    It is called "Defensive programming", see for example https://en.wikipedia.org/wiki/... or chapter 8 of Code Complete 2
  • 0
    I had a coworker once who would reassign variables in a catch block. It was horrible 😅
  • 1
    Well this is useful if ur on a team of monkeys without unit tests.

    This comment says to me: if this happens, you've screwed up something so bad that you better fix it or else...
  • 0
    Should that else have a throw inside?
  • 2
    How about

    if (condition) {
    // do nothing
    } else {
    doStuff()
    }

    Saw this a few times, you ask why? I've asked the same thing, the response: "well it works this way, the compiler will optimize it anyways and how else would you do it?"

    ... FUUUUUUUUUUUUCK HOW ABOUT PUTTING A FUCKING ! INFRLNT OF THAT MOTHERFUCKING CONDITION?!? YOU STUPID SHITFUCK!
Add Comment