195
fana-m
8y

browsing application source, found this beauty of a method 😶

Comments
  • 0
    been there, seen that
  • 4
    really? Really?

    it's just

    if (final >= 1 && final <= 6)
    return final;
    return -1;
  • 20
    @rainmitchell Take a closer look, case 4 returns 5 and 5 returns 4 😜
  • 8
    @Folkmann oh shit... Why the fuck are they doing that? I give up...
  • 11
    Been there, wrote that.
  • 15
    Ternaries would be fun here and look no less stupid.

    (status == 5) ? return 4 : ((status == 4) ? return 5 : ((status > 0) ? return status : return -1))
  • 5
    Looks maintainable to me, keep up the good work! *shoots himself*
  • 1
    @rainmitchell really really...maybe they never finished it
  • 1
    @-bgm- You're right, it does look stupid
  • 11
    I think it's a beautiful block of code
    #allCodeMatters
  • 8
    .......at least it's indented...
  • 0
    Somebody did this for the cringe
  • 0
    @-bgm- except that's broken, it should of only return status if its > 0 and <= 6
  • 0
    @port22 let's say it's ready for expansion.
  • 8
    This really is the best solution. Take a close look, case 4 returns 5 and case 5 returns 4. You could use the ternary posted above but it's broken, the last conditional should be (status >= 1 && status <= 6) but now you have a ternary which is ugly and not inherently obvious what it does. Also your breaking convention by using a ternary operator > 80 characters. What happens when the spec changes and now 9 should return 14? If I'm using the ternary solution instead of just adding a case I have to interpret the ternary and realize I should put the new conditional before the last one. Shit on it all you want but the switch statement is the most maintainable and readable solution here. The one thing he/she could've done to improve it was added comments pointing out the 4 and 5 are switched and why.
  • 0
    Anybody know what application this is from?
  • 0
    @port22 you mean environment? Looks like c# in visual studio.
  • 6
    Some PM obviously said "is it possible to switch place of the fourth and fifth item in the list?" And dev says "Sure, it is built with this kind of flexibility in mind, it's a oneliner!".
    Backs are patted and salaries are raised...
  • 1
    #SpecChange
  • 0
    If you want to maintain this method, just add an annotation "please don't touch" because I would have changed this method as @rainmitchell said and fucked up the code xD (i didn't notice the 4 & 5 switch too).
Add Comment