12

If got to do some bugfixing at work today.
Looking through code:

if (x !== undefined || x !== null){

I want the person who wrote this to wear the ugliest and scratchiest christmas sweater with "i write bad code" written on it

Comments
  • 5
    Inb4 you realise it was you
  • 3
    @j4cobgarby nope, i had my ups and downs but i never named a function get0
  • 0
    @YouAreAPIRate that's what they named it? Oh dear
  • 1
    @j4cobgarby worst of all, they copy-pasted the function right above it and added some code at the end of the copy. They propably didn't realize they could use the result from the previous function...
  • 4
    Does it return 0?
  • 1
    @bashleigh no, it returns the index 0 of some array
  • 3
    What.... fucking hell XD so arr[0]? are.length > 1 ? @YouAreAPIRate
  • 1
    @bashleigh it's something like

    arr = this.someOtherFunc();
    return arr[0] !== undefined ? arr[0].id: undefined;
  • 0
    @YouAreAPIRate I just puked a little...
  • 1
    @PonySlaystation i should do this at work, now i only need someone to certify this perfectly valid medical condition
  • 1
    Wtf is !== Why it's not !=
    What language is that?
  • 0
    @Vitz it's javascript. Javascripts == operator has a history of fails, based on the design of the language. E.g. [[[2]]] == 2 returns true, same for 0 == "\t".
    Because of that the === operator was introduced which also checks the types of the operands
  • 1
    @YouAreAPIRate
    You don't have an equals or instanceof? 3 times =? Seriously? Who is the genius to make that up...
    Good thing they stopped at 3.... Moreover Javascript not smart enough to realize when 2 different types are being compared...
  • 0
    @Vitz there is a typeof, but what do you prefer?
    a === b
    Or
    typeof a == typeof b && a == b

    That's just the way a language born from browser wars works, it's the same with html parsing. Every browser had his own rules and exceptions and then there's backwards compatibility.
  • 0
    @YouAreAPIRate
    I would prefer a.equals(b) for value and == for reference.
    Or even better, never check for null unless it's on the UI level, always return empty objects because you can iterate them because it will just do nothing.
Add Comment