Like most people, I have my own preferences for code layout. I tend to use more horizintal whitespace and less vertical than other people.

But the single most important rule in my book is:

Above all, be consistent!
.

Personally, I'm gonna code new code, my way. This less through beligerance than the simple fact that having to stop and think about style, rather than letting it flow naturally, imposes too high a price in terms of distraction from the task of programming.

If client rules absolutely insist, I'll use a code beautifier to re-format my code to the "house style" when I'm done with it, or at checkin. With most code editors it is fairly easy to set up macros to run the beautifier to house rules and then do check in and to my preference on checkout.

That said, when I pick up someone elses code, if I am only browsing or making a simple change, then I'll skip the reformating, if they have a consistant style. It is generally fairly easy to aquire a good eye for whatever style is used, if it is used consistantly.

If they don't, and/or I need to get a good understanding of their code, I'll more often than not reformat their code by hand, line by line, from the top to bottom. I find that the process of going through the code doing this forces me to actually read each line rather than just scanning it.

Reading and familiarising yourself with a piece of code, even a piece of your own from a few months ago is the single best way of avoiding making silly mistakes. It only takes a few minutes to do and saves so much time in the long run.

Generally, I am pretty skeptical of the "simple code avoids maintenance problems" argument. Personally, it is rarely making changes to moderately complex code where I make silly mistakes. It is the quick, "obvious" changes to simple code, where the mistakes creep in.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

In reply to Re: PBP: Code Layout by BrowserUk
in thread PBP: Code Layout by saberworks

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.