Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • 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
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. What was the most interesting, funny or silly Code you have ever read?

What was the most interesting, funny or silly Code you have ever read?

Scheduled Pinned Locked Moved The Weird and The Wonderful
question
54 Posts 36 Posters 0 Views 1 Watching
  • 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.
  • A Aadhar Joshi

    Where 1=1 I mean that is obvious..

    T Offline
    T Offline
    The Sql Coder
    wrote on last edited by
    #13

    yes it could happen

    1 Reply Last reply
    0
    • B Brisingr Aerowing

      if (this == null)
      {
      //WTF just happened?!?!!
      Environment.Exit(-1);
      }

      I cannot remember the exact code block, but it was something along those lines. And yes, somehow, that condition happened. And 'this' was the actual keyword, not some redefinition of it. I still don't know how that one happened.

      I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image. Stephen Hawking

      S Offline
      S Offline
      Sentenryu
      wrote on last edited by
      #14

      your object was finalized before the time, probably it had a unmanaged reference, when it had no more managed references, the GC collected it... Forgeting to pin a object is really a PITA, especially when it's the first time you are doing P/Invoke :sigh: (i was speaking of me, not sure if this is your case)

      I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)

      B 1 Reply Last reply
      0
      • U User 8545351

        At the Company i am working in the Intellicence gave me These two methods. Microcernel.Create(). 1. PrintLabel() 2. PrintLable() Both methods contained the same oneliner. this._Label();

        F Offline
        F Offline
        Fran Porretto
        wrote on last edited by
        #15

        A professor of Computer Science -- a world-renowned expert on PL/I -- once wrote the following: if ((i != 1) || (i != 2)) ... else ... (Yes, the above is in C. I can't remember the PL/I syntax.) He spent most of a day trying to figure out why the "else" branch was never executed. A graduate programming assistant had to point it out to him. (This message is programming you in ways you cannot detect. Be afraid.)

        1 Reply Last reply
        0
        • U User 8545351

          At the Company i am working in the Intellicence gave me These two methods. Microcernel.Create(). 1. PrintLabel() 2. PrintLable() Both methods contained the same oneliner. this._Label();

          J Offline
          J Offline
          JiveCode
          wrote on last edited by
          #16

          if (my $thisScriptHasBecomeSkynet) {
          die;
          }

          1 Reply Last reply
          0
          • U User 8545351

            At the Company i am working in the Intellicence gave me These two methods. Microcernel.Create(). 1. PrintLabel() 2. PrintLable() Both methods contained the same oneliner. this._Label();

            S Offline
            S Offline
            Stuart Rubin
            wrote on last edited by
            #17

            When I first saw this comment, I thought it was ridiculous, but now I see a lot of beauty in the f actuality and irony of it. Here it is: // Note that there are 1024 milliseconds in a second

            1 Reply Last reply
            0
            • B Bernhard Hiller

              That's a good point to start complex WHERE clauses. Just add all other constraints with an AND X=Y. You do not need to worry if the statement is the first statement (no AND required) or not (AND required).

              F Offline
              F Offline
              Fabio Franco
              wrote on last edited by
              #18

              That's specially useful when you need to constantly comment in and out some of the conditions to find the right records. Without that you'd have to worry to every time replace the AND for a WHERE and vice-versa.

              To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson ---- Our heads are round so our thoughts can change direction - Francis Picabia

              J 1 Reply Last reply
              0
              • U User 8545351

                At the Company i am working in the Intellicence gave me These two methods. Microcernel.Create(). 1. PrintLabel() 2. PrintLable() Both methods contained the same oneliner. this._Label();

                B Offline
                B Offline
                BrainiacV
                wrote on last edited by
                #19

                You mean aside from this[^]? At one place I worked, we were under deadline and a coworker was going to take some time off. He said his part of the project was done and tested. He gave me a copy to integrate into my code and went on vacation. I installed it and it promptly fell on its face. Looking through the code, it was a complete mess. I ended up taking a hatchet to it, but one routine caught my eye. It was supposed to center some text on a line. Instead of taking the length of the line, subtracting the length of the string, then dividing by two to get the number of spaces to print before the string, he instead created a string of spaces for the length of the line, overlaid the string at the beginning, and then iteratively added spaces at the beginning and removed spaces at the end until they were equal or the leading spaces was longer than the trailing spaces. It was the only routine that worked and I left it in place to illustrate the type of code I had to deal with. I still tried to cover for him, but since rewriting his code impacted the development of my code, when the manager came by breathing fire because I was falling behind, I had to show his work to her. When he came by after his vacation I showed him my changes, he said, "Yes, that's my code." I snarled internally that this bozo couldn't even recognize his code and how I had changed it (chopped 1/3 or more of it out) and then I advised him to take a tube of KY Jelly with him to his meeting with our supervisor because I knew she was going to ream him out.

                Psychosis at 10 Film at 11 Those who do not remember the past, are doomed to repeat it. Those who do not remember the past, cannot build upon it.

                1 Reply Last reply
                0
                • U User 8545351

                  At the Company i am working in the Intellicence gave me These two methods. Microcernel.Create(). 1. PrintLabel() 2. PrintLable() Both methods contained the same oneliner. this._Label();

                  P Offline
                  P Offline
                  Patrick Fox
                  wrote on last edited by
                  #20

                  It wasn't funny at the time, but any VB.Net code that looked like this is hilarious in retrospect:

                  try

                  ' lots of statements

                  catch
                  end try

                  Or even worse:

                  On Error Resume Next

                  ' lots of statements

                  The developer's excuse? "My code doesn't crash!" Yeah. It also didn't work.

                  P 1 Reply Last reply
                  0
                  • C Clark Kent123

                    My favorite that I have seen is this...

                    if variable < 24 And variable > 26 then
                    '...
                    end if

                    R Offline
                    R Offline
                    Ronald A
                    wrote on last edited by
                    #21

                    it could be a 'typo' for an Or :)

                    C 1 Reply Last reply
                    0
                    • P Patrick Fox

                      It wasn't funny at the time, but any VB.Net code that looked like this is hilarious in retrospect:

                      try

                      ' lots of statements

                      catch
                      end try

                      Or even worse:

                      On Error Resume Next

                      ' lots of statements

                      The developer's excuse? "My code doesn't crash!" Yeah. It also didn't work.

                      P Offline
                      P Offline
                      Phil_Murray
                      wrote on last edited by
                      #22

                      This one has it beat.

                      P M 2 Replies Last reply
                      0
                      • P Phil_Murray

                        This one has it beat.

                        P Offline
                        P Offline
                        Patrick Fox
                        wrote on last edited by
                        #23

                        That's downright scary. I insist that people use C# so they don't get into bad habits like that.

                        1 Reply Last reply
                        0
                        • B Brisingr Aerowing

                          if (this == null)
                          {
                          //WTF just happened?!?!!
                          Environment.Exit(-1);
                          }

                          I cannot remember the exact code block, but it was something along those lines. And yes, somehow, that condition happened. And 'this' was the actual keyword, not some redefinition of it. I still don't know how that one happened.

                          I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image. Stephen Hawking

                          S Offline
                          S Offline
                          SeattleC
                          wrote on last edited by
                          #24

                          Zac Greve wrote:

                          //WTF just happened?!?!! Environment.Exit(-1);

                          Way back in the 1980's, I was using Sun 3 workstations running UNIX. We had FrameMaker, back before Adobe got ahold of it. On UNIX, there is a command called "strings" that attempts to extract all the ASCII strings from a file. If you ran it over FrameMaker.exe, one of the strings you got was... "Evacuate now? In our moment of triumph? I think you overestimate their chances." There is no way to tell what error case causes this message to print, or just what happens right after, but I really want to know.

                          1 Reply Last reply
                          0
                          • U User 8545351

                            At the Company i am working in the Intellicence gave me These two methods. Microcernel.Create(). 1. PrintLabel() 2. PrintLable() Both methods contained the same oneliner. this._Label();

                            M Offline
                            M Offline
                            Member 8414600
                            wrote on last edited by
                            #25

                            in FORTH: Begin ... if ( swap ) ... until then The parentheses allow you to leave the compiler, so the swap changes the addresses on the stack so the straddled begin and if statements worked.

                            S 1 Reply Last reply
                            0
                            • U User 8545351

                              At the Company i am working in the Intellicence gave me These two methods. Microcernel.Create(). 1. PrintLabel() 2. PrintLable() Both methods contained the same oneliner. this._Label();

                              F Offline
                              F Offline
                              ForestHymn
                              wrote on last edited by
                              #26

                              This is going back many years, and from memory it went something like this:

                              - (bool)is_even(int value)
                              {
                              if (value == 0)
                              {
                              return true;
                              }
                              else if (value == 2)
                              {
                              return true;
                              }
                              else if (value == 4)
                              {
                              return true;
                              }
                              ...
                              else if (value == 12)
                              {
                              return true;
                              }

                              return false;
                              

                              }

                              And so it went to 12 and I guess for the context in which it was used it apparently was a high enough number. You could of course replace this method using a simple modulus operation. What's also funny is that I saw this code in a printout on the wall of an engineer, which had been there for a couple years. A short time after, another engineer, new to the group, found this method still existing in another part of the code base (apparently just copy-pasted from its original location). The code base was very large. Lesson learned is if you find bad code somewhere do a global search to insure it is not duplicated anywhere else.

                              U H 2 Replies Last reply
                              0
                              • P Phil_Murray

                                This one has it beat.

                                M Offline
                                M Offline
                                Mike Marynowski
                                wrote on last edited by
                                #27

                                Hahaha, level: advanced, and spent all day on it. So many levels of humor in that article...mind blown.

                                1 Reply Last reply
                                0
                                • S Sentenryu

                                  your object was finalized before the time, probably it had a unmanaged reference, when it had no more managed references, the GC collected it... Forgeting to pin a object is really a PITA, especially when it's the first time you are doing P/Invoke :sigh: (i was speaking of me, not sure if this is your case)

                                  I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)

                                  B Offline
                                  B Offline
                                  Brisingr Aerowing
                                  wrote on last edited by
                                  #28

                                  This wasn't my code, it was from one of my friend's projects. I cannot remember what the actual class did, but most of the projects code files were naive (and buggy) implementations of classes in the framework. I did show him the documentation, and his reply was "Cool! How did you know this existed?". Me: :doh:

                                  I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image. Stephen Hawking

                                  S 1 Reply Last reply
                                  0
                                  • B Brisingr Aerowing

                                    This wasn't my code, it was from one of my friend's projects. I cannot remember what the actual class did, but most of the projects code files were naive (and buggy) implementations of classes in the framework. I did show him the documentation, and his reply was "Cool! How did you know this existed?". Me: :doh:

                                    I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image. Stephen Hawking

                                    S Offline
                                    S Offline
                                    Sentenryu
                                    wrote on last edited by
                                    #29

                                    PEBKAC :-\

                                    I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)

                                    B 1 Reply Last reply
                                    0
                                    • S Sentenryu

                                      PEBKAC :-\

                                      I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)

                                      B Offline
                                      B Offline
                                      Brisingr Aerowing
                                      wrote on last edited by
                                      #30

                                      I think it was more of an ID-Ten-T error. Either that or a BrainNotFoundException. He has decided to become an English Major with Anthropology and History minors. :doh:

                                      I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image. Stephen Hawking

                                      S 1 Reply Last reply
                                      0
                                      • B Brisingr Aerowing

                                        if (this == null)
                                        {
                                        //WTF just happened?!?!!
                                        Environment.Exit(-1);
                                        }

                                        I cannot remember the exact code block, but it was something along those lines. And yes, somehow, that condition happened. And 'this' was the actual keyword, not some redefinition of it. I still don't know how that one happened.

                                        I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image. Stephen Hawking

                                        Y Offline
                                        Y Offline
                                        Yann Bane
                                        wrote on last edited by
                                        #31

                                        Which language is that? Java?

                                        1 Reply Last reply
                                        0
                                        • C Clark Kent123

                                          Uhhhh... sure! :) Just kidding. The programmer at the time just probably forgot that they checked the same variable twice. Maybe it was supposed to be another variable. I have no clue what the intention was, but its still active in the program. I don't have the heart to comment it out because of how funny the goof is. :laugh:

                                          J Offline
                                          J Offline
                                          Jagsir
                                          wrote on last edited by
                                          #32

                                          int main (){
                                          long variable = -1;

                                              long var24 = 24;
                                              unsigned long var26 = 26;
                                          
                                              if( variable < var24 && (variable > var26)){
                                                      printf("%ld, is a magic number, %lu, %ld, %ld", variable, variable, var24, var26);
                                              }
                                              return 0;
                                          

                                          }

                                          I was just wondering if this could come up somewhere in the code and still be funny. -JD

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

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