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. Brings back memories [modified]

Brings back memories [modified]

Scheduled Pinned Locked Moved The Weird and The Wonderful
20 Posts 14 Posters 9 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.
  • D Offline
    D Offline
    D111
    wrote on last edited by
    #1

    After reading a few posts on this forum, it makes me remember some horrible code I have written before. (While I was a VB5 programmer) It also reminds me of some horrible code I've seen some other people write, like the following:

    private bool isValid(int testValue, int minValue, int maxValue)
    {
    for (int counter = minValue; counter <= maxValue; counter++)
    {
    if (testValue == counter)
    {
    return true;
    }
    else
    {
    if (counter == maxValue)
    {
    return false;
    }
    }
    }
    }

    To make matters worse, they then called this method a few hundred times with min and max Values of 0 and about 500.

    --- The sum of the intelligence of the world is constant. The total number of people is always increasing.

    J S I P M 10 Replies Last reply
    0
    • D D111

      After reading a few posts on this forum, it makes me remember some horrible code I have written before. (While I was a VB5 programmer) It also reminds me of some horrible code I've seen some other people write, like the following:

      private bool isValid(int testValue, int minValue, int maxValue)
      {
      for (int counter = minValue; counter <= maxValue; counter++)
      {
      if (testValue == counter)
      {
      return true;
      }
      else
      {
      if (counter == maxValue)
      {
      return false;
      }
      }
      }
      }

      To make matters worse, they then called this method a few hundred times with min and max Values of 0 and about 500.

      --- The sum of the intelligence of the world is constant. The total number of people is always increasing.

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      Nice, that's a brilliant little horror. p.s. use <pre> tags around your code instead of <code> tags. <pre> tags will preserve the whitespace.

      Tech, life, family, faith: Give me a visit. I'm currently blogging about: Master's Decree: It's By My Spirit (audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

      D 1 Reply Last reply
      0
      • D D111

        After reading a few posts on this forum, it makes me remember some horrible code I have written before. (While I was a VB5 programmer) It also reminds me of some horrible code I've seen some other people write, like the following:

        private bool isValid(int testValue, int minValue, int maxValue)
        {
        for (int counter = minValue; counter <= maxValue; counter++)
        {
        if (testValue == counter)
        {
        return true;
        }
        else
        {
        if (counter == maxValue)
        {
        return false;
        }
        }
        }
        }

        To make matters worse, they then called this method a few hundred times with min and max Values of 0 and about 500.

        --- The sum of the intelligence of the world is constant. The total number of people is always increasing.

        S Offline
        S Offline
        Sylvester george
        wrote on last edited by
        #3

        hmmm awesome:((

        Regards, Sylvester G sylvester_g_m@yahoo.com

        1 Reply Last reply
        0
        • D D111

          After reading a few posts on this forum, it makes me remember some horrible code I have written before. (While I was a VB5 programmer) It also reminds me of some horrible code I've seen some other people write, like the following:

          private bool isValid(int testValue, int minValue, int maxValue)
          {
          for (int counter = minValue; counter <= maxValue; counter++)
          {
          if (testValue == counter)
          {
          return true;
          }
          else
          {
          if (counter == maxValue)
          {
          return false;
          }
          }
          }
          }

          To make matters worse, they then called this method a few hundred times with min and max Values of 0 and about 500.

          --- The sum of the intelligence of the world is constant. The total number of people is always increasing.

          I Offline
          I Offline
          Ian Shlasko
          wrote on last edited by
          #4

          Hey, don't knock VB5... Back in the day, it was pretty amazing if you were too lazy/rushed to learn the MFC. As for the code... Wow... Nice one.

          1 Reply Last reply
          0
          • D D111

            After reading a few posts on this forum, it makes me remember some horrible code I have written before. (While I was a VB5 programmer) It also reminds me of some horrible code I've seen some other people write, like the following:

            private bool isValid(int testValue, int minValue, int maxValue)
            {
            for (int counter = minValue; counter <= maxValue; counter++)
            {
            if (testValue == counter)
            {
            return true;
            }
            else
            {
            if (counter == maxValue)
            {
            return false;
            }
            }
            }
            }

            To make matters worse, they then called this method a few hundred times with min and max Values of 0 and about 500.

            --- The sum of the intelligence of the world is constant. The total number of people is always increasing.

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            Oh, man, I never thought of doing that.

            C 1 Reply Last reply
            0
            • J Judah Gabriel Himango

              Nice, that's a brilliant little horror. p.s. use <pre> tags around your code instead of <code> tags. <pre> tags will preserve the whitespace.

              Tech, life, family, faith: Give me a visit. I'm currently blogging about: Master's Decree: It's By My Spirit (audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

              D Offline
              D Offline
              D111
              wrote on last edited by
              #6

              I've just modified it to use

              tags


              The sum of the intelligence of the world is constant. The total number of people is always increasing.

              1 Reply Last reply
              0
              • P PIEBALDconsult

                Oh, man, I never thought of doing that.

                C Offline
                C Offline
                CPallini
                wrote on last edited by
                #7

                PIEBALDconsult wrote:

                Oh, man, I never thought of doing that.

                I saw the following formatting masterpiece:

                int nTotalMinutes; // Total time expressed in minutes

                int nHours=0;
                int nMinutes=0;
                while (nTotalMinutes >= 60)
                {
                nTotalMinutes -= 60;
                nHours++;
                }
                printf("Time %d:%d\n", nHours, nMinutes);

                The above snippet only illustrates the concept because, if I remember well, the starting point were nTotalSeconds! :-D

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                M L 2 Replies Last reply
                0
                • C CPallini

                  PIEBALDconsult wrote:

                  Oh, man, I never thought of doing that.

                  I saw the following formatting masterpiece:

                  int nTotalMinutes; // Total time expressed in minutes

                  int nHours=0;
                  int nMinutes=0;
                  while (nTotalMinutes >= 60)
                  {
                  nTotalMinutes -= 60;
                  nHours++;
                  }
                  printf("Time %d:%d\n", nHours, nMinutes);

                  The above snippet only illustrates the concept because, if I remember well, the starting point were nTotalSeconds! :-D

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                  M Offline
                  M Offline
                  Michael Sadlon
                  wrote on last edited by
                  #8

                  Why, oh why? Use modulus, pleeaaassee :doh:

                  C 1 Reply Last reply
                  0
                  • D D111

                    After reading a few posts on this forum, it makes me remember some horrible code I have written before. (While I was a VB5 programmer) It also reminds me of some horrible code I've seen some other people write, like the following:

                    private bool isValid(int testValue, int minValue, int maxValue)
                    {
                    for (int counter = minValue; counter <= maxValue; counter++)
                    {
                    if (testValue == counter)
                    {
                    return true;
                    }
                    else
                    {
                    if (counter == maxValue)
                    {
                    return false;
                    }
                    }
                    }
                    }

                    To make matters worse, they then called this method a few hundred times with min and max Values of 0 and about 500.

                    --- The sum of the intelligence of the world is constant. The total number of people is always increasing.

                    M Offline
                    M Offline
                    Michael Sadlon
                    wrote on last edited by
                    #9

                    private bool isValid(int testValue, int minValue, int maxValue)
                    {
                    return ( (minValue <= testValue) && (testValue <= maxValue) );
                    }

                    Fixed :laugh:

                    X 1 Reply Last reply
                    0
                    • D D111

                      After reading a few posts on this forum, it makes me remember some horrible code I have written before. (While I was a VB5 programmer) It also reminds me of some horrible code I've seen some other people write, like the following:

                      private bool isValid(int testValue, int minValue, int maxValue)
                      {
                      for (int counter = minValue; counter <= maxValue; counter++)
                      {
                      if (testValue == counter)
                      {
                      return true;
                      }
                      else
                      {
                      if (counter == maxValue)
                      {
                      return false;
                      }
                      }
                      }
                      }

                      To make matters worse, they then called this method a few hundred times with min and max Values of 0 and about 500.

                      --- The sum of the intelligence of the world is constant. The total number of people is always increasing.

                      P Offline
                      P Offline
                      Pete OHanlon
                      wrote on last edited by
                      #10

                      At one time or another, we've all coded a horror. I know I have:-D

                      Deja View - the feeling that you've seen this post before.

                      1 Reply Last reply
                      0
                      • M Michael Sadlon

                        Why, oh why? Use modulus, pleeaaassee :doh:

                        C Offline
                        C Offline
                        CPallini
                        wrote on last edited by
                        #11

                        Simply because they weren't able to use it... :-D

                        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                        1 Reply Last reply
                        0
                        • M Michael Sadlon

                          private bool isValid(int testValue, int minValue, int maxValue)
                          {
                          return ( (minValue <= testValue) && (testValue <= maxValue) );
                          }

                          Fixed :laugh:

                          X Offline
                          X Offline
                          Xiangyang Liu
                          wrote on last edited by
                          #12

                          In case you did not notice, the original code has a "bug". If maxValue is less than minValue, then the function may not return anything. In any case, your code is not equivalent to the original code because: isValid(1, 1, 0) returns true with the original code. isValid(1, 1, 0) returns false with your code. Releasing code without testing is dangerous, isn't it? :-D

                          My .NET Business Application Framework My Home Page

                          P 2 Replies Last reply
                          0
                          • D D111

                            After reading a few posts on this forum, it makes me remember some horrible code I have written before. (While I was a VB5 programmer) It also reminds me of some horrible code I've seen some other people write, like the following:

                            private bool isValid(int testValue, int minValue, int maxValue)
                            {
                            for (int counter = minValue; counter <= maxValue; counter++)
                            {
                            if (testValue == counter)
                            {
                            return true;
                            }
                            else
                            {
                            if (counter == maxValue)
                            {
                            return false;
                            }
                            }
                            }
                            }

                            To make matters worse, they then called this method a few hundred times with min and max Values of 0 and about 500.

                            --- The sum of the intelligence of the world is constant. The total number of people is always increasing.

                            R Offline
                            R Offline
                            Ravi Bhavnani
                            wrote on last edited by
                            #13

                            Thankfully, this won't even compile using the VS2005 C# compiler. :) /ravi

                            This is your brain on Celcius Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

                            1 Reply Last reply
                            0
                            • X Xiangyang Liu

                              In case you did not notice, the original code has a "bug". If maxValue is less than minValue, then the function may not return anything. In any case, your code is not equivalent to the original code because: isValid(1, 1, 0) returns true with the original code. isValid(1, 1, 0) returns false with your code. Releasing code without testing is dangerous, isn't it? :-D

                              My .NET Business Application Framework My Home Page

                              P Offline
                              P Offline
                              PIEBALDconsult
                              wrote on last edited by
                              #14

                              Xiangyang Liu wrote:

                              isValid(1, 1, 0) returns true with the original code.

                              No, the loop wouldn't be entered, so it would return... ummm... oh yeah, that's why it won't compile; "Not all code paths..."

                              1 Reply Last reply
                              0
                              • D D111

                                After reading a few posts on this forum, it makes me remember some horrible code I have written before. (While I was a VB5 programmer) It also reminds me of some horrible code I've seen some other people write, like the following:

                                private bool isValid(int testValue, int minValue, int maxValue)
                                {
                                for (int counter = minValue; counter <= maxValue; counter++)
                                {
                                if (testValue == counter)
                                {
                                return true;
                                }
                                else
                                {
                                if (counter == maxValue)
                                {
                                return false;
                                }
                                }
                                }
                                }

                                To make matters worse, they then called this method a few hundred times with min and max Values of 0 and about 500.

                                --- The sum of the intelligence of the world is constant. The total number of people is always increasing.

                                J Offline
                                J Offline
                                John R Shaw
                                wrote on last edited by
                                #15

                                Is that VB5 code? I was forced to write in VB6 once and the code you presented would not have compiled. I understand why this is a coding horror – who ever wrote it needs to find a new line of work. P.S. I am still having trouble believing what I am seeing.

                                INTP "Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra

                                1 Reply Last reply
                                0
                                • X Xiangyang Liu

                                  In case you did not notice, the original code has a "bug". If maxValue is less than minValue, then the function may not return anything. In any case, your code is not equivalent to the original code because: isValid(1, 1, 0) returns true with the original code. isValid(1, 1, 0) returns false with your code. Releasing code without testing is dangerous, isn't it? :-D

                                  My .NET Business Application Framework My Home Page

                                  P Offline
                                  P Offline
                                  PIEBALDconsult
                                  wrote on last edited by
                                  #16

                                  the original code has a "bug". If maxValue is less than minValue

                                  That may be true if the intent is to determine whether or not the test value "is between" the other two values; which is likely, but may not be the case. As to improving the efficiency of the routine... I've had bosses who would say, "It's always been that way, don't change it." And colleagues who would say, "It ain't broke, don't fix it." In one memorable case I bloody well did fix it, and the result was that the program took ten minutes to run rather than forty... and I was out of a job. Yes, I'd do it again.

                                  1 Reply Last reply
                                  0
                                  • C CPallini

                                    PIEBALDconsult wrote:

                                    Oh, man, I never thought of doing that.

                                    I saw the following formatting masterpiece:

                                    int nTotalMinutes; // Total time expressed in minutes

                                    int nHours=0;
                                    int nMinutes=0;
                                    while (nTotalMinutes >= 60)
                                    {
                                    nTotalMinutes -= 60;
                                    nHours++;
                                    }
                                    printf("Time %d:%d\n", nHours, nMinutes);

                                    The above snippet only illustrates the concept because, if I remember well, the starting point were nTotalSeconds! :-D

                                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                                    L Offline
                                    L Offline
                                    Lost User
                                    wrote on last edited by
                                    #17

                                    mov eax, dword [nTotalMinutes]
                                    xor edx, edx
                                    mov ebx, 60
                                    div ebx
                                    cinvoke printf, <"Time %d:%d",0x10>, eax, edx

                                    I heart assembly.:-D

                                    C 1 Reply Last reply
                                    0
                                    • L Lost User

                                      mov eax, dword [nTotalMinutes]
                                      xor edx, edx
                                      mov ebx, 60
                                      div ebx
                                      cinvoke printf, <"Time %d:%d",0x10>, eax, edx

                                      I heart assembly.:-D

                                      C Offline
                                      C Offline
                                      CPallini
                                      wrote on last edited by
                                      #18

                                      sk8er_boy287 wrote:

                                      I heart assembly

                                      Expecially when a single instruction perform two operations:-D Not available to us, poor C programmers:(( :)

                                      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                                      1 Reply Last reply
                                      0
                                      • D D111

                                        After reading a few posts on this forum, it makes me remember some horrible code I have written before. (While I was a VB5 programmer) It also reminds me of some horrible code I've seen some other people write, like the following:

                                        private bool isValid(int testValue, int minValue, int maxValue)
                                        {
                                        for (int counter = minValue; counter <= maxValue; counter++)
                                        {
                                        if (testValue == counter)
                                        {
                                        return true;
                                        }
                                        else
                                        {
                                        if (counter == maxValue)
                                        {
                                        return false;
                                        }
                                        }
                                        }
                                        }

                                        To make matters worse, they then called this method a few hundred times with min and max Values of 0 and about 500.

                                        --- The sum of the intelligence of the world is constant. The total number of people is always increasing.

                                        R Offline
                                        R Offline
                                        Russell Jones
                                        wrote on last edited by
                                        #19

                                        took a long time to work out what that code actually does. I kept looking at it and thinking "No surely that's not it". Now i realise that that is the true horror of this creation. On top of that i can only guess the result of having testvalue > maxvalue but i guess as a private method it can expect sanitised input. wow, Russ

                                        1 Reply Last reply
                                        0
                                        • D D111

                                          After reading a few posts on this forum, it makes me remember some horrible code I have written before. (While I was a VB5 programmer) It also reminds me of some horrible code I've seen some other people write, like the following:

                                          private bool isValid(int testValue, int minValue, int maxValue)
                                          {
                                          for (int counter = minValue; counter <= maxValue; counter++)
                                          {
                                          if (testValue == counter)
                                          {
                                          return true;
                                          }
                                          else
                                          {
                                          if (counter == maxValue)
                                          {
                                          return false;
                                          }
                                          }
                                          }
                                          }

                                          To make matters worse, they then called this method a few hundred times with min and max Values of 0 and about 500.

                                          --- The sum of the intelligence of the world is constant. The total number of people is always increasing.

                                          D Offline
                                          D Offline
                                          DynV
                                          wrote on last edited by
                                          #20

                                          OMFG ! :laugh: Did his manager review ANY of his work ?

                                          Je vous salue du Québec !

                                          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