Open Menu
AllLocalCommunitiesAbout
lotide
AllLocalCommunitiesAbout
Login

I wish

⁨874⁩ ⁨likes⁩

Submitted ⁨⁨1⁩ ⁨year⁩ ago⁩ by ⁨nave@lemmy.zip⁩ to ⁨[deleted]⁩

https://i.imgur.com/31qxtlZ.png

source

Comments

Sort:hotnewtop
  • wtry@lemm.ee ⁨1⁩ ⁨year⁩ ago

    bool iseven(int number){ if (number % 2 == 0){ return true; } else { return false; } }

    source
    • TopRamenBinLaden@sh.itjust.works ⁨1⁩ ⁨year⁩ ago

      I like the example in the post better. It is more clear as to what is going on to an experienced dev like me. What’s this 2 percent nonsense?

      source
      • EvokerKing@lemmy.world ⁨1⁩ ⁨year⁩ ago

        Explanation: the percent is modulus. Basically it’s just divide the first number by the second and return the remainder. If you do number % 2, it will return 1 if it is odd and 0 if it is even. For example 4/2 has a remainder of 0 and therefore is even. 3/2 has a remainder of 1, and therefore is odd.

        source
        • -> View More Comments
      • Clearwatermo@lemmy.world ⁨1⁩ ⁨year⁩ ago

        I like the example in the comment better. It is more confusing as to what is going on to an experienced dev like me. iSeven is always odd tho right?

        source
        • -> View More Comments
      • filcuk@lemmy.zip ⁨1⁩ ⁨year⁩ ago

        Readability over obscure hacks

        source
        • -> View More Comments
    • infreq@lemmy.world ⁨1⁩ ⁨year⁩ ago

      Whooosh

      source
      • Kingofthevoid@lemmy.world ⁨1⁩ ⁨year⁩ ago

        Whoosh

        source
  • pinkdrunkenelephants@lemmy.cafe ⁨1⁩ ⁨year⁩ ago

    Modulus equals zero anyone?

    source
    • ramenshaman@lemmy.world ⁨1⁩ ⁨year⁩ ago

      That’s the joke

      source
    • nogrub@lemmy.world ⁨1⁩ ⁨year⁩ ago

      but that operation is expensive

      source
      • pinkdrunkenelephants@lemmy.cafe ⁨1⁩ ⁨year⁩ ago

        So what? It works and it’s better than precompiling a list of all known even and odd numbers, and expecting a computer to iterate through a whole list every time it wants to check the value of something.

        The stupid trig tables are just as problematic and it’s why graphics chips use other geometric functions instead. It’s just better to use a modulus.

        source
        • -> View More Comments
      • Rubeer@sh.itjust.works ⁨1⁩ ⁨year⁩ ago

        Nah, it compiles down to an AND because of the constant 2

        source
  • postmateDumbass@lemmy.world ⁨1⁩ ⁨year⁩ ago

    They really should mod the language to support this.

    source
  • Cosmicomical@lemmy.world ⁨1⁩ ⁨year⁩ ago

    There is a simpler way: all the "else if"s can be replaced with simple "if"s

    source
    • Valmond@lemmy.mindoki.com ⁨1⁩ ⁨year⁩ ago

      You mean make it even worse.(performance wise)? Interesting.

      source
      • mryessir@lemmy.sdf.org ⁨1⁩ ⁨year⁩ ago

        Please elaborate. When and why would his suggestion be worse?

        source
        • -> View More Comments
  • superpants@lemm.ee ⁨1⁩ ⁨year⁩ ago

    I did something like this in high school

    source
  • Clbull@lemmy.world ⁨1⁩ ⁨year⁩ ago

    I, EvaX, humbly submit a toast to Nicholas Alexander for successfully managing to pirate WarCraft III so that he may play Defense of the Ancients.

    Congratulations Nick, enjoy your DotA!

    (sips from cum chalice)

    source
    • wtry@lemm.ee ⁨1⁩ ⁨year⁩ ago
      • cum
      source
      • Clbull@lemmy.world ⁨1⁩ ⁨year⁩ ago

        Image

        source
  • Flax_vert@feddit.uk ⁨1⁩ ⁨year⁩ ago

    Rip switch statements

    source