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. Magic Numbers

Magic Numbers

Scheduled Pinned Locked Moved The Weird and The Wonderful
10 Posts 6 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 Offline
    A Offline
    Adrian Tawse
    wrote on last edited by
    #1

    On the subject of completelystupid programmers I one came accross this. Someone had told this idiot that literal cnstants (magic numbers) were "a bad thing", so the benighed fool hd produces a file containint the following: #define ZERO 0 #define ONE 1 #define TWO 2 #define THREE 3 ... #define TEN_THOUSAND 10000 and included it in every source file. And this is the absolute truth, no kidding.

    A _ 2 Replies Last reply
    0
    • A Adrian Tawse

      On the subject of completelystupid programmers I one came accross this. Someone had told this idiot that literal cnstants (magic numbers) were "a bad thing", so the benighed fool hd produces a file containint the following: #define ZERO 0 #define ONE 1 #define TWO 2 #define THREE 3 ... #define TEN_THOUSAND 10000 and included it in every source file. And this is the absolute truth, no kidding.

      A Offline
      A Offline
      AspDotNetDev
      wrote on last edited by
      #2

      While that is a coding horror, I would hate to read your code comments.

      Adrian.Tawse wrote:

      completelystupid

      Adrian.Tawse wrote:

      cnstants

      Adrian.Tawse wrote:

      benighed

      Adrian.Tawse wrote:

      hd

      Adrian.Tawse wrote:

      containint

      :omg:

      [Forum Guidelines]

      F 1 Reply Last reply
      0
      • A AspDotNetDev

        While that is a coding horror, I would hate to read your code comments.

        Adrian.Tawse wrote:

        completelystupid

        Adrian.Tawse wrote:

        cnstants

        Adrian.Tawse wrote:

        benighed

        Adrian.Tawse wrote:

        hd

        Adrian.Tawse wrote:

        containint

        :omg:

        [Forum Guidelines]

        F Offline
        F Offline
        fjdiewornncalwe
        wrote on last edited by
        #3

        Give him a break... His profile says he is in the UK.... :)

        I wasn't, now I am, then I won't be anymore.

        A 1 Reply Last reply
        0
        • F fjdiewornncalwe

          Give him a break... His profile says he is in the UK.... :)

          I wasn't, now I am, then I won't be anymore.

          A Offline
          A Offline
          AspDotNetDev
          wrote on last edited by
          #4

          And after 4 years, that was the first time he's posted, so he's not yet aware of the abuse he'll receive for poor spelling. :rolleyes:

          [Forum Guidelines]

          A 1 Reply Last reply
          0
          • A AspDotNetDev

            And after 4 years, that was the first time he's posted, so he's not yet aware of the abuse he'll receive for poor spelling. :rolleyes:

            [Forum Guidelines]

            A Offline
            A Offline
            Adrian Tawse
            wrote on last edited by
            #5

            Mea culpa, mea culpa, mea maxima culpa. I was wearing the wrong glasses. And now for a new snippet: A software package was being put together for release and a colleague remarked of one item "Oh God, not that pile of shit". I asked why and he said that it corrupted floppies. Now this was before the days when the FAT file system was build into Unix. The utility attempted to write Unix files to a DOS FAT floppy. It did this by opening the device in RAW mode and read and wrote whole sectors, including the FAT table. When transferring text files it would read a sector’s worth of data, scan for \n, shift everything up one, and insert \r. This, of course, would result in buffer overflow. What followed the buffer in memory? You guessed it, the FAT table, which was duly written back to the floppy at the end; it took about ten seconds to notice the problem. I went to the Team Leader to say “You cannot possibly ship this; I can fix it in minutes”. His reply was that they had had a summer student in ad it had taken him all summer to do that, and on no account was I to touch a line; it was to ship exactly as is. “It is OK when used with newly formatted floppies, and the file is not too big” I am not sure who I was more amazed with, the summer student or the Team Leader.

            A 1 Reply Last reply
            0
            • A Adrian Tawse

              On the subject of completelystupid programmers I one came accross this. Someone had told this idiot that literal cnstants (magic numbers) were "a bad thing", so the benighed fool hd produces a file containint the following: #define ZERO 0 #define ONE 1 #define TWO 2 #define THREE 3 ... #define TEN_THOUSAND 10000 and included it in every source file. And this is the absolute truth, no kidding.

              _ Offline
              _ Offline
              _Erik_
              wrote on last edited by
              #6

              Worse things can be seen:

              int ONE_HUNDRED = 100;

              // Some really weird code and... Surprise!!
              ONE_HUNDRED++;

              OriginalGriffO 1 Reply Last reply
              0
              • _ _Erik_

                Worse things can be seen:

                int ONE_HUNDRED = 100;

                // Some really weird code and... Surprise!!
                ONE_HUNDRED++;

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

                If it's any consolation, I've seen FORTRAN compilers which which will allow the equivalent of the following:

                public void inc(ref int i)
                {
                i *= 2;
                }
                ...
                Console.WriteLine(100);
                inc(100);
                Console.WriteLine(100);
                ...

                And would print:

                100
                200

                And I had to find that in production code...:mad:

                Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

                "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
                • OriginalGriffO OriginalGriff

                  If it's any consolation, I've seen FORTRAN compilers which which will allow the equivalent of the following:

                  public void inc(ref int i)
                  {
                  i *= 2;
                  }
                  ...
                  Console.WriteLine(100);
                  inc(100);
                  Console.WriteLine(100);
                  ...

                  And would print:

                  100
                  200

                  And I had to find that in production code...:mad:

                  Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

                  _ Offline
                  _ Offline
                  _Erik_
                  wrote on last edited by
                  #8

                  LOOOOL!! This is me while reading your post: :) :-D :omg: :wtf: Thanks for sharing such a pearl. :thumbsup:

                  A 1 Reply Last reply
                  0
                  • _ _Erik_

                    LOOOOL!! This is me while reading your post: :) :-D :omg: :wtf: Thanks for sharing such a pearl. :thumbsup:

                    A Offline
                    A Offline
                    Adrian Tawse
                    wrote on last edited by
                    #9

                    I have been a Contractor for 35 years. In that time I have been on about 40 or so projects most of which have been at least partial disasters. Some day I will write the whole gory details. I will make you belly laugh, then very very depressed.

                    1 Reply Last reply
                    0
                    • A Adrian Tawse

                      Mea culpa, mea culpa, mea maxima culpa. I was wearing the wrong glasses. And now for a new snippet: A software package was being put together for release and a colleague remarked of one item "Oh God, not that pile of shit". I asked why and he said that it corrupted floppies. Now this was before the days when the FAT file system was build into Unix. The utility attempted to write Unix files to a DOS FAT floppy. It did this by opening the device in RAW mode and read and wrote whole sectors, including the FAT table. When transferring text files it would read a sector’s worth of data, scan for \n, shift everything up one, and insert \r. This, of course, would result in buffer overflow. What followed the buffer in memory? You guessed it, the FAT table, which was duly written back to the floppy at the end; it took about ten seconds to notice the problem. I went to the Team Leader to say “You cannot possibly ship this; I can fix it in minutes”. His reply was that they had had a summer student in ad it had taken him all summer to do that, and on no account was I to touch a line; it was to ship exactly as is. “It is OK when used with newly formatted floppies, and the file is not too big” I am not sure who I was more amazed with, the summer student or the Team Leader.

                      A Offline
                      A Offline
                      Anna Jayne Metcalfe
                      wrote on last edited by
                      #10

                      That is organisationally crap on so many levels. :doh:

                      Anna :rose: Tech Blog | Visual Lint "Why would anyone prefer to wield a weapon that takes both hands at once, when they could use a lighter (and obviously superior) weapon that allows you to wield multiple ones at a time, and thus supports multi-paradigm carnage?"

                      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