Your state of mind is the biggest factor in your coding.

The second point also sounds wise, but that first statement resonates very strongly with me. Allow me to share an anecdote...

One evening, back when I was learning C, I'd spent a hour or two reading Snow Crash by Neal Stephenson. Perhaps this primed my mind in some way for what followed. :)

I sat down and began coding... but my 'state of mind' was singular. I don't think I've ever been that focused. I began writing a routine to convert strings containing numbers in arbitrary bases to their numeric values... in Perl terms, this was a super oct().

I spent perhaps two hours total. My mind seemed very clear, and I thought through the problem in depth... I probably spent 20 minutes doing nothing but thinking between brief periods of typing. At the end - I hadn't yet heard of TDD, you see :) - I ran my code and started testing it. It worked the first time. Perfectly. Everything happened exactly as I expected. I made no changes to the code after that, because there were no more to make. My memory's a bit fuzzy, but I think I also had a routine to do the reverse operation, and that worked perfectly too. I was shocked.

I know I've improved since then and today I could probably find an edge case or two to break that code. But at the time, it was an amazing, almost transcendent experience. I couldn't believe I'd produced what I had.

So I concur - it's the biggest factor. This begs the question... What techniques do the monks have for 'focusing'? How do you enter 'deep hack mode'? Perhaps I should start a new thread. :)

email: perl -e 'print scalar reverse map { chr( ord($_)-1 ) } split //, "ufo/hojsfufqAofc";'

In reply to Re^2: Avoiding silly programming mistakes by missingthepoint
in thread Avoiding silly programming mistakes by missingthepoint

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, 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, 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.