Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

agnos.is Forums

  1. Home
  2. Programmer Humor
  3. Infallible Code

Infallible Code

Scheduled Pinned Locked Moved Programmer Humor
programmerhumor
52 Posts 40 Posters 3 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K [email protected]

    Better/fastest approch would be to check the last bit of the int and return the result.
    Second use modulo.

    This? Dev should burn in hell.
    Who created this?

    cows_are_underrated@feddit.orgC This user is from outside of this forum
    cows_are_underrated@feddit.orgC This user is from outside of this forum
    [email protected]
    wrote on last edited by
    #16

    Alternatively you can divide by 2, turn it into an int, mtiply it by 2 and check if both numbers are the same.

    1 Reply Last reply
    8
    • cm0002@lemmy.worldC [email protected]
      This post did not contain any content.
      M This user is from outside of this forum
      M This user is from outside of this forum
      [email protected]
      wrote on last edited by
      #17

      At least this madness is isolated to this function. It can easily be fixed.

      Pirate’s code is just cluttered with magic numbers everywhere. Hard coded numbers that are referring to a big ”story array”, or characters. It’s just a giant web of complexity. The only fix is to start from scratch.

      L 1 Reply Last reply
      11
      • cm0002@lemmy.worldC [email protected]
        This post did not contain any content.
        themoonisacheese@sh.itjust.worksT This user is from outside of this forum
        themoonisacheese@sh.itjust.worksT This user is from outside of this forum
        [email protected]
        wrote on last edited by
        #18

        Obligatory: https://codegolf.stackexchange.com/q/275739/88192

        L 1 Reply Last reply
        3
        • grilledcheese@lemmy.blahaj.zoneG [email protected]

          This isn’t his actual code, right? Like this specific code pictured here? I’m aware of the “drama” surrounding him currently.

          lime@feddit.nuL This user is from outside of this forum
          lime@feddit.nuL This user is from outside of this forum
          [email protected]
          wrote on last edited by
          #19

          this is an old meme about yanderedev

          1 Reply Last reply
          9
          • cm0002@lemmy.worldC [email protected]
            This post did not contain any content.
            S This user is from outside of this forum
            S This user is from outside of this forum
            [email protected]
            wrote on last edited by [email protected]
            #20

            After working at blizzard for 51 years, I finally found an elegant solution by using the power of recursion

            private bool IsEven(int number){
              if (number > 1) return IsEven(number - 2);
              if (number == 0) return true;
              if (number == 1) return false;
            }
            
            E E 2 Replies Last reply
            75
            • K [email protected]

              Better/fastest approch would be to check the last bit of the int and return the result.
              Second use modulo.

              This? Dev should burn in hell.
              Who created this?

              T This user is from outside of this forum
              T This user is from outside of this forum
              [email protected]
              wrote on last edited by [email protected]
              #21

              or another stupid, but viable way to do it,

              if number = 0:

              return true

              runloop = true

              while runloop:

              if number > 0:

              number -= 2

              else:

              number += 2

              if number = 1:

              return false

              runloop = false

              if number = 2:

              return true

              runloop = false

              still very shitty amature coding, doesn't depend on modulos, or anything that I can think of that some languages might lack an equivelant of.

              1 Reply Last reply
              2
              • S [email protected]

                After working at blizzard for 51 years, I finally found an elegant solution by using the power of recursion

                private bool IsEven(int number){
                  if (number > 1) return IsEven(number - 2);
                  if (number == 0) return true;
                  if (number == 1) return false;
                }
                
                E This user is from outside of this forum
                E This user is from outside of this forum
                [email protected]
                wrote on last edited by
                #22
                assert IsEven(-2);
                
                lambda@programming.devL 1 Reply Last reply
                37
                • S [email protected]

                  After working at blizzard for 51 years, I finally found an elegant solution by using the power of recursion

                  private bool IsEven(int number){
                    if (number > 1) return IsEven(number - 2);
                    if (number == 0) return true;
                    if (number == 1) return false;
                  }
                  
                  E This user is from outside of this forum
                  E This user is from outside of this forum
                  [email protected]
                  wrote on last edited by
                  #23

                  I removed the tail recursion for you:

                  private book IsEven(int number) {
                      if(number > 1) return IsEven(number - 2) == true;
                      if(number == 0) return true; 
                      if(number == 2) return false;
                  }
                  
                  U F 2 Replies Last reply
                  13
                  • E [email protected]

                    I removed the tail recursion for you:

                    private book IsEven(int number) {
                        if(number > 1) return IsEven(number - 2) == true;
                        if(number == 0) return true; 
                        if(number == 2) return false;
                    }
                    
                    U This user is from outside of this forum
                    U This user is from outside of this forum
                    [email protected]
                    wrote on last edited by
                    #24

                    I didn't get this.

                    Why return book? Does that have some Blizzard reference?
                    And why would number == 2 ⇒ return false? This is a function for getting true when the number is even, right?

                    E 1 Reply Last reply
                    4
                    • cm0002@lemmy.worldC [email protected]
                      This post did not contain any content.
                      _cnt0@sh.itjust.works_ This user is from outside of this forum
                      _cnt0@sh.itjust.works_ This user is from outside of this forum
                      [email protected]
                      wrote on last edited by
                      #25

                      Not to take from all the funny answers ... but

                      bool IsEven(int i) => (i & 1) != 1;
                      

                      (C#)

                      _cnt0@sh.itjust.works_ 1 Reply Last reply
                      2
                      • U [email protected]

                        I didn't get this.

                        Why return book? Does that have some Blizzard reference?
                        And why would number == 2 ⇒ return false? This is a function for getting true when the number is even, right?

                        E This user is from outside of this forum
                        E This user is from outside of this forum
                        [email protected]
                        wrote on last edited by [email protected]
                        #26

                        Haha, you're right. I've now learned two things:

                        1. I should not write code on a mobile
                        2. I should not become a proof reader

                        At the end of the day i just wanted the function to be worse, by causing stack overflows

                        1 Reply Last reply
                        12
                        • _cnt0@sh.itjust.works_ [email protected]

                          Not to take from all the funny answers ... but

                          bool IsEven(int i) => (i & 1) != 1;
                          

                          (C#)

                          _cnt0@sh.itjust.works_ This user is from outside of this forum
                          _cnt0@sh.itjust.works_ This user is from outside of this forum
                          [email protected]
                          wrote on last edited by
                          #27

                          Though, obviously I had to come up with some ridiculous solutions:

                          bool IsEven(int i) => ((Func<string, bool>)(s => s[^1] == 48))($"{i:B}");
                          

                          This one works without conditionals 🙂

                          bool IsEven(int i)
                          {
                              try
                              {
                                  int _ = (i & 1) / (i & 1);
                              }
                              catch (Exception)
                              {
                                  return true;
                              }
                          
                              return false;
                          }
                          
                          L 1 Reply Last reply
                          0
                          • cm0002@lemmy.worldC [email protected]
                            This post did not contain any content.
                            typewar@infosec.pubT This user is from outside of this forum
                            typewar@infosec.pubT This user is from outside of this forum
                            [email protected]
                            wrote on last edited by
                            #28

                            Lol the amount of bullying this guy is getting lately. I've seen similar spins and bends that looks somewhat legit, making people believe he suck at coding

                            1 Reply Last reply
                            8
                            • cm0002@lemmy.worldC [email protected]
                              This post did not contain any content.
                              tux0r@feddit.orgT This user is from outside of this forum
                              tux0r@feddit.orgT This user is from outside of this forum
                              [email protected]
                              wrote on last edited by
                              #29

                              Then again, Duff’s Device works rather similarly.

                              1 Reply Last reply
                              4
                              • xxce2aab@feddit.dkX [email protected]

                                Pah, mathematicians and their generally applicable pure approach to solutions and fancy modulus operations, who needs 'em? Computing is applied and we always work with well-defined finite precision. Granted, writing the boilerplate for all possible 64 bit integers is a bit laborious, but we're programmers! That's what code generation is for.

                                J This user is from outside of this forum
                                J This user is from outside of this forum
                                [email protected]
                                wrote on last edited by
                                #30

                                Granted, writing the boilerplate for all possible 64 bit integers is a bit laborious,

                                I've been trying to figure out roughly how many lines of code that would equal out to but I've run out of fingers.

                                xxce2aab@feddit.dkX 1 Reply Last reply
                                1
                                • M [email protected]

                                  I worked at Blizzard. I worked at Blizzard. I worked at Blizzard.

                                  L This user is from outside of this forum
                                  L This user is from outside of this forum
                                  [email protected]
                                  wrote on last edited by
                                  #31

                                  Yeah, but did your dad work at Blizzard??

                                  M 1 Reply Last reply
                                  13
                                  • M [email protected]

                                    At least this madness is isolated to this function. It can easily be fixed.

                                    Pirate’s code is just cluttered with magic numbers everywhere. Hard coded numbers that are referring to a big ”story array”, or characters. It’s just a giant web of complexity. The only fix is to start from scratch.

                                    L This user is from outside of this forum
                                    L This user is from outside of this forum
                                    [email protected]
                                    wrote on last edited by
                                    #32

                                    It's simple. The only problem is that your code sucks!

                                    1 Reply Last reply
                                    3
                                    • _cnt0@sh.itjust.works_ [email protected]

                                      Though, obviously I had to come up with some ridiculous solutions:

                                      bool IsEven(int i) => ((Func<string, bool>)(s => s[^1] == 48))($"{i:B}");
                                      

                                      This one works without conditionals 🙂

                                      bool IsEven(int i)
                                      {
                                          try
                                          {
                                              int _ = (i & 1) / (i & 1);
                                          }
                                          catch (Exception)
                                          {
                                              return true;
                                          }
                                      
                                          return false;
                                      }
                                      
                                      L This user is from outside of this forum
                                      L This user is from outside of this forum
                                      [email protected]
                                      wrote on last edited by
                                      #33

                                      s[^1]

                                      Ohh wow, I've been learning it casually for years, and I didn't know that existed in C#. I guess I should go back and hit the books some more.

                                      1 Reply Last reply
                                      0
                                      • P This user is from outside of this forum
                                        P This user is from outside of this forum
                                        [email protected]
                                        wrote on last edited by
                                        #34

                                        If small numbers are much more frequent, it's better to return early. Really, you should gather statistics about the numbers the function is called with, and put the most frequent ones at the top.

                                        1 Reply Last reply
                                        2
                                        • themoonisacheese@sh.itjust.worksT [email protected]

                                          Obligatory: https://codegolf.stackexchange.com/q/275739/88192

                                          L This user is from outside of this forum
                                          L This user is from outside of this forum
                                          [email protected]
                                          wrote on last edited by
                                          #35

                                          The fuck is that

                                          themoonisacheese@sh.itjust.worksT 1 Reply Last reply
                                          1
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups