You've already got the answer you wanted, but an amusing (to me and one workmate at least, although not amusing to another) example may be appreciated.

A workmate and I were working through refactoring and understanding some code (C++, but not really relevant to the story) that another workmate had written. The code concerned used circular buffers at the end of a calculation chain for feeding samples into a digital to analog converter. Getting the size of the buffer right is a critical part of making the system work correctly. We encountered a few lines that were used to configure the buffers and looked something like:

mOutBuffer = CreateBuffer(baseBufferSize+3*2*k10HzKneeSampleBufferSize +);

We couldn't figure out what the 3 * 2 was doing in there and there were no comments to give any clue so we changed it to:

#define PI 3.1415 // Circular buffers mOutBuffer = CreateBuffer(baseBufferSize + 2 * PI * k10HzKneeSampleBuf +ferSize);

which we at least thought amusing. We hoped that the other workmate would appreciate the joke then provide some sort of sensible name for the constant and perhaps a useful comment. Instead, at the next scrum he noted that someone had added a PI constant "probably they thought it was amusing" and it wasn't right!

Sadly the PI constant is still in the code and we still don't really know why that particular value is used. There was no doubt a clue in the value being written as 3 * 2, but it escaped us.

So, that's a classic magic number. It's critical to correct operation of the code, but provides not obvious rational for its selection.

And if you read a little friction in the team between the lines, you are right. The person who wrote that part of the code is very bright, but I think he has trouble appreciating that not everyone understands stuff in the way he does.

Premature optimization is the root of all job security

In reply to Re^3: Perl vs Python revisited by GrandFather
in thread Perl vs Python revisited by QuillMeantTen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.