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.
  • 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
    • 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
      sappo
      wrote on last edited by
      #33

      this following jQuery nugget:

      if ( $('#'+src.id).parent().parent().next().children().children('.dvSpeakerBio').is(":visible") )
      {
      $('#'+src.id).parent().parent().next().hide();
      $('#'+src.id).parent().parent().next().children().children('.dvSpeakerBio').hide();
      $('.speaker').removeClass('selectedSpeaker');
      $('.alt_speaker').css('background-color', '#f6f6f6');
      }

      1 Reply Last reply
      0
      • L LloydA111

        I'm not sure, but I've always thought it would be funny to leave this in some code and see people's faces:

        if(10 != 10){
        abort();
        }

        =====
        \ | /
        \|/
        |
        |-----|
        | |
        |_ |
        _) | /
        _) __/_
        _) ____
        | /|
        | / |
        | |
        |-----|
        |

        ===

        M Offline
        M Offline
        Member 4608898
        wrote on last edited by
        #34

        I've seen that in older Fortran programs on compilers for systems that didn't have comparison against constants in their assembly language. They saved zero in a particular location and all comparisons were done against that location. Occasionally, someone would unknowingly pass 0 into a routine in the parameter position where the value was changed by the routine. That is when zero stopped becoming zero and was something completely different. It read something like if ((0+1) .ne. 1) call abend

        1 Reply Last reply
        0
        • F ForestHymn

          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 Offline
          U Offline
          User 8545351
          wrote on last edited by
          #35

          Haha I am sure i have read this in a book or programming tutorial as an example for bad code.

          1 Reply Last reply
          0
          • B Brisingr Aerowing

            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 Offline
            S Offline
            Sentenryu
            wrote on last edited by
            #36

            :doh: well, can't say i haven't found such cases... there was a guy on my class who left to become a surgeon... I hope I never have to be operated by him :~

            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)

            1 Reply Last reply
            0
            • M Member 8414600

              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 Offline
              S Offline
              Sentenryu
              wrote on last edited by
              #37

              :~

              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)

              1 Reply Last reply
              0
              • R Ronald A

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

                C Offline
                C Offline
                Clark Kent123
                wrote on last edited by
                #38

                That was my thoughts exactly. However, there are many other instances like the example I posted. The worse I have seen are many goto statements.

                1 Reply Last reply
                0
                • A Aadhar Joshi

                  Where 1=1 I mean that is obvious..

                  D Offline
                  D Offline
                  dxk241
                  wrote on last edited by
                  #39

                  I have seen that code in a VB6 app and it was a convenient way to get an empty but initialized (containing columns you were interested in) RecordSet from the database that you could then populate with data and save.

                  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();

                    D Offline
                    D Offline
                    dxk241
                    wrote on last edited by
                    #40

                    For me, it was a WinForms app written in VB.NET that was using hidden Textbox controls on the form as a Boolean variable!!! The whole app was full with checks for true/false against a Textbox.Text property instead of simply declaring a boolean variable.

                    B 1 Reply Last reply
                    0
                    • D dxk241

                      For me, it was a WinForms app written in VB.NET that was using hidden Textbox controls on the form as a Boolean variable!!! The whole app was full with checks for true/false against a Textbox.Text property instead of simply declaring a boolean variable.

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

                      X| That one just is.... blech. Was this... programmer (I use the term loosely here)... a new guy? Or someone who knew nothing about what they were working with (e.g. PEBKAC o ID-Ten-T)?

                      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

                      D 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
                        BlackMilan
                        wrote on last edited by
                        #42

                        Don't know if my most interesting/funny/silly but some of the last I found. Comments should help to better understand ... maybe!

                        if (anyBooleanValue == false)
                        { // in case of true
                        ...
                        }
                        else
                        { // in case of false
                        ...
                        }

                        ...
                        return; // leave the method
                        

                        Twice are better ...

                        DataTable dt = new DataTable();
                        dt = otherTable.Copy();
                        
                        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();

                          C Offline
                          C Offline
                          Chris Quinn
                          wrote on last edited by
                          #43

                          I once had to work on a package (in an 3G language/database called Dataflex if anyone remembers it) that contained the following remarkd

                          The following is Himalayan Mountain Climber code, and so is impenetrable to us mere mortals!

                          When I asked what this meant, I was told that it had been written by a contractor, whose hobby was indeed climbing in the Himalayas, who was known for using all sorts of undocumented tricks to provide very clever and efficient code that nobody else could understand.

                          ==================================== Transvestites - Roberts in Disguise! ====================================

                          1 Reply Last reply
                          0
                          • L LloydA111

                            I'm not sure, but I've always thought it would be funny to leave this in some code and see people's faces:

                            if(10 != 10){
                            abort();
                            }

                            =====
                            \ | /
                            \|/
                            |
                            |-----|
                            | |
                            |_ |
                            _) | /
                            _) __/_
                            _) ____
                            | /|
                            | / |
                            | |
                            |-----|
                            |

                            ===

                            J Offline
                            J Offline
                            jsc42
                            wrote on last edited by
                            #44

                            This variant is better for perplexing beginners:

                            if ( 010 == 10 || 07 != 7) {
                            abort();
                            }

                            (The test is false [ 010 is not equal to 10, but 07 is equal to 7 ] in most C derived languages)

                            1 Reply Last reply
                            0
                            • F Fabio Franco

                              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 Offline
                              J Offline
                              jsc42
                              wrote on last edited by
                              #45

                              Fabio Franco wrote:

                              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.

                              For that, I use TRUE, e.g. in SQL:

                              WHERE TRUE
                              AND X=Y
                              AND A=B

                              You can then comment in / out the real conditions without any worries about whether a leading AND is needed or not or even if any conditions remain. e.g.

                              WhereClause = "WHERE TRUE "
                              & ( test1wanted ? "AND X=Y " : "" )
                              & ( test2wanted ? "AND A=B " : "" );

                              F 1 Reply Last reply
                              0
                              • J jsc42

                                Fabio Franco wrote:

                                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.

                                For that, I use TRUE, e.g. in SQL:

                                WHERE TRUE
                                AND X=Y
                                AND A=B

                                You can then comment in / out the real conditions without any worries about whether a leading AND is needed or not or even if any conditions remain. e.g.

                                WhereClause = "WHERE TRUE "
                                & ( test1wanted ? "AND X=Y " : "" )
                                & ( test2wanted ? "AND A=B " : "" );

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

                                Same thing, except "1=1" is only three characters long :)

                                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
                                • F Fabio Franco

                                  Same thing, except "1=1" is only three characters long :)

                                  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 Offline
                                  J Offline
                                  jsc42
                                  wrote on last edited by
                                  #47

                                  My apologies! I had misread your previous comment.

                                  F 1 Reply Last reply
                                  0
                                  • J jsc42

                                    My apologies! I had misread your previous comment.

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

                                    No need to ;)

                                    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

                                    1 Reply Last reply
                                    0
                                    • L LloydA111

                                      I'm not sure, but I've always thought it would be funny to leave this in some code and see people's faces:

                                      if(10 != 10){
                                      abort();
                                      }

                                      =====
                                      \ | /
                                      \|/
                                      |
                                      |-----|
                                      | |
                                      |_ |
                                      _) | /
                                      _) __/_
                                      _) ____
                                      | /|
                                      | / |
                                      | |
                                      |-----|
                                      |

                                      ===

                                      D Offline
                                      D Offline
                                      Doug Henderson
                                      wrote on last edited by
                                      #49

                                      I worked on a system where the Fortran compiler generated constants in memory locations. All subroutine calls used pass by reference, so it was very easy for a constant to get changed. And very difficult to debug with the tools available in that day and age.

                                      OriginalGriffO 1 Reply Last reply
                                      0
                                      • D Doug Henderson

                                        I worked on a system where the Fortran compiler generated constants in memory locations. All subroutine calls used pass by reference, so it was very easy for a constant to get changed. And very difficult to debug with the tools available in that day and age.

                                        OriginalGriffO Offline
                                        OriginalGriffO Offline
                                        OriginalGriff
                                        wrote on last edited by
                                        #50

                                        Prime OS had that, as well as GEC (IIRC) It made for some "interesting" debugging the first couple of times it happened, but then you leant not to trust constants! :laugh:

                                        Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

                                        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                                        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                                        1 Reply Last reply
                                        0
                                        • F ForestHymn

                                          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.

                                          H Offline
                                          H Offline
                                          HaBiX
                                          wrote on last edited by
                                          #51

                                          private bool IsEven(int number) {
                                          return (new[] { 0, 2, 4, 6, 8 }).Contains(number.ToString()[number.ToString().Length - 1]);
                                          }

                                          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