14

This is called "programming efficiency"

Comments
  • 4
    I bet they used GitHub co-pilot :D
  • 5
    Perfect example for the harm of stupid metrics like lines of code...

    Int modulus is a single assembly instruction.
  • 1
    Where does it stop?
  • 2
    @jespersh

    That might indeed one of the rare cases where the unit test is shorter than the subject under test - while still covering all code paths and edge cases.
  • 1
    If only there was a simpler way to do it...
  • 1
    @asgs At 2147483647
  • 0
    @12bitfloat looking at that code, I don't think so
  • 3
    I don't understand how this can be tolerated. Is this in a work environment, or? That would be weird. This isn't even tolerated in highschool. lol.

    Is a number even? Hm, *me as junior dev*:

    return (num % 2 == 0)
  • 2
    @asgs it doesn't, it's now an open source project.
  • 2
    @CaptainRant no that's on reddit (:
  • 6
    You can optimize away all the "else" because each if is returning.
    Otherwise I see no problem.
  • 1
    I'd call it the cause of termination.
  • 0
    @rEaL-jAsE Damn, I just suck at the syntax lol
  • 0
    @rEaL-jAsE Wait my actual content just got deletet ??? Now that's a bruh moment
  • 1
    Um ok....this is a little scary. I mean I admire this “dev’s” patience to type all that shit up, but the least he could’ve done was google how to check even instead of going this route and cracking his carpals
  • 0
    @rEaL-jAsE that was a joke
  • 2
    @TeachMeCode I mean this is clearly a very good way of spending your Saturday.
  • 1
    What's the default return? based on that, you can delete at least half those lines
  • 0
    @Oktokolo but it's a hefty one. Not that it warrants this crap but modulo and divide are the heavies.

    Let's say you don't know about modulo and don't know how build your own divide by two nothing remaining stuff.
    At least notice that you have a binary option that can be solved with if else (false in the else).
    That would have saved half the rules already.
  • 0
    @hjk101

    Yeah: bool isEven(uint i) => i ^ 1 == 1.
  • 0
    @Oktokolo I think you mean
    bool isEven(uint i) => !(i & 1)

    But I‘d assume that modern processors will do modulo at least as fast as this and/or the compiler optimizes it anyway.

    @hjk101

    Never do premature optimization unless you can prove that modulo is slower and has a measurable impact!
  • 1
    @Lensflare

    Yep, looks like i had a brainfart there.
  • 0
    Yeah you're right. They should have made it recursive 🤣
Add Comment