122

The worst Code I saw was

if (value != null ) {
return value;
} else {
return null;
}

Comments
  • 7
    How to waste 5 lines of code
  • 2
    Welcome to optional unwrapping in Swift. It's really good tho.
  • 7
    Not even in the top 10 worst for me
  • 3
    There could actually be a purpose to this in JavaScript, even though it could be written more concisely.

    Not having strict equals means falsy values like 0, "" or undefined will be turned into null.

    Coffeescript turns the existential operator for something like:
    foobar?
    into
    (foobar != null)
    for this specific purpose of catching all falsy values.
  • 2
    One more worse code:

    def funct(a):
    return a
    if a is None:
    return "bad input"
  • 2
    I sometimes write code like this mainly so I can add extra logic in the future. Saves time down the line.
  • 0
    I don't know what to think 😀
  • 1
    //stuff here
    unsigned int v;
    // more stuff here
    If (v <0){
    //Do Something of Important(*)
    }
    //again stuff
  • 1
    This makes total sense in JS. It will return both null and undefined as null, but pass valid values trough (especially relevant for falsy ones like "" and 0).
Add Comment