2
urco
14h

Rank Best to worst code readability
Mine 6,3,1,4,2,5

Comments
  • 7
    It gets worse the longer you look at it. Returning a string and not a boolean is making my skin crawl.
  • 2
    I wont. But i will do one or two, based on my mood.

    Btw, who the fuck are you? Welome back i guess :)
  • 2
    I wont. But i will do one or two, based on my mood.
  • 0
    1, 2, 3 depends on the case. For short stuff ternary is ok. For longer stuff, if else. For early returns "2" is ok.

    4 is a no go as it utilizes mutation for no good reason.

    5 seems fabricated. No one would use that (i hope)

    6 seems similarly fabricated. Who would use switch for a boolean condition?
  • 1
    @retoor Oh no, snek crashed!
  • 1
    @cuddlyogre you made me realize that it doesn’t return bool. I assume it was a mistake ^^
  • 3
    I would say 2 > 3 > 1 and the rest are just bad
  • 1
    @12bitfloat yeah, new server doesn't seem that stable. My laptop at home has stable ssh connection for days but my new server doesn't.
  • 1
    const isEven = n => !!(n%2)

    const getOddness = n => isEven(n)? 'even': 'odd'
  • 1
    1: correct. Normal and good. Not great, you could use a lambda.

    2. Kinda weird. You probably eat your own dickcheese.

    3. You're sort of ok but I still don't like you.

    4. What the absolute shit is wrong with you?????? WHY would you do that at all. Your mummy probably shaked you real good and now your brain is compressed you FUCKING weirdo. I HATE YOU!! NOW IM GONNA HAVE TO GO TO SLEEP HAVING SEEN THAT SHIT. IF I EVER SEE THAT SHIT AGAIN I CHALLENGE YOU TO A DUEL!!!!!!!!!!!

    5. Kinda smart, but you're a showoff, which mean you have a limp dick. I will still judge you.

    6. Booooring. Go buy a butt plug and live a little.
  • 0
    I like 6, 1, and 2.

    Bad function name too. isEven() or isOdd() would read better (it would return a bool value)

    It breaks single responsibility principle a bit as it's handling both a "calculation" (if it can be called that) to determine a state AND it's then handling formatting that in some kind of human readable _response_

    This is by no means the worst code I've seen but it isn't great
  • 0
    Cute poll OP I hope you do more
  • 1
    If this is Typescript, the analyzer will treat the return type as a sort of enum, 'Even' | 'Odd'. It's still weird in this use, but in practice it wouldn't be bad.
  • 0
    I would rather anonymous function / lambda instead of function

    and that switch statement makes me want rust's match

    also typing "return". oh no I can never go back now
  • 1
    You know that using a switch instead of an if is a performance hit, right?

    Before someone comes to nitpick, I know the compiler will likely elide it, that it is a miiiiinor performance gain otherwise, and yadda yadda yadda.

    If no one's life depends on it, just do whatever. Chances are whoever comes next to you is gonna give you shit no matter what choice you pick.
  • 0
    you forgot the part where you ask GPT

    npm i is-odd

    this package will do it for you easy peasy.
  • 0
    3: ok. 1: also ok. 2: no. 5: wtf but I kind of like it. 4: fuck off. 6: fuck off.
  • 2
    1 is the way, everything else is trash
  • 0
    1, 3, 6, 2, 4, 5
  • 0
    1, 2, 3, 6, 4, 5

    If I didn't have the other examples, I woudln't even get what 5 does.
  • 0
    @kiki This is the way.
  • 0
    1,2,3,4,6,5...

    5 is just bad with the array allocation too
Add Comment