171

I never believed in such posts until I saw this today.....

*Double face palm*

Comments
  • 13
    Woah. That's some useless spaghetti.
  • 46
    That developer must get paid by how many lines of code he writes... that's my only explanation.
  • 2
    Someone should choose a different career!
  • 2
    here is a third face palm :|
  • 5
    Even better than 11 if..else..statements.

    (Although this code could be replaced by one if)
  • 5
    Use goto ! Dumbass...

    👌
  • 3
    @Strannch someone disliked my "goto hell" statement in code
    (:hell at line 365974)
  • 4
    There's an entire subreddit for this. I think it's r/badcode
  • 7
    @spa69 hell should be at line 666 😉
  • 2
    What if, I'm not saying it probably is, but what if the different items aren't numbered in a nice order. Maybe Item 4 is the integer -847736, and item 5 is the integer 45, and maybe there are many more values in that item enum not visible to us...
    Then it might, only saying it might, be easier to do it this way if you want to model the behaviour of always returning item 1 by default....

    Staying humble has never failed me yet.
  • 3
    Kill him.
    Bury him in the second page of Google results about "Rubber Duck".
  • 1
    I'm pretty sure this source code come from a class that extends RecyclerView. Adapter.
  • 1
    I love the default:
  • 1
    I think shortest way to do the same is
    switch(position) {
    case TYPE_ITEM_1:
    case TYPE_ITEM_2:
    ...
    case TYPE_ITEM_10:
    return position;
    default:
    return TYPE_ITEM_1;
    }

    Anyways, ithat functions is a signal that you need a serious refactor
  • 7
    Shortest way for the same result would be:

    if (position > 10) {
    return 1;
    }
    return position;
  • 2
    @jralph you don't know if these const are these ints
  • 0
    Try coding Apex. Doesn't have switch.
  • 1
    @Gianlu the Sherlock in disguise you're correct! 😉
  • 0
    @jralph cheers buddy! That's exactly what I added (but with index 0).

    Yeah, they were integer constants only. 😅
  • 0
    @ryanmhoffman There was a post about this a long time ago...
  • 0
    Whoever it was, was just trying to be “visually” thorough.
  • 0
    Absolutely useless. Love to see where he calls this method.
  • 2
    Ah, OK...

    No harm in double assigning, just in case, maybe it should be repeated with if statements in a try catch, just in case.

    Then maybe create a unit test for that, just in case, just in case.

    Did I say just in case? Just in case I'm going to say - just in case.
  • 0
  • 0
    @lazyDev do you need a couple more hands?
  • 2
    Can't believe it this is a production code. No seriously, what's wrong with people?
  • 1
    X = X ?? 1
  • 0
    replace the whole switch-case with return position;
  • 0
    I cringed when i saw this like the first time i googled trypophobia and saw an image of it.
  • 0
    @Letmecode totally unrelated! Just got the same type of "cringe" feeling
Add Comment