in reply to Different ways of formatting/writing code

I use the 'cuddled else' style for subroutines, else-constructs, eval-blocks, actually for blocks in general. I indent the content of a block by one 'tab' stop (four spaces) and out-dent the terminating curly-brace on its own separate line foe visual distinction. That is my personal preference.

My text-editor (Vim with a set of macros; thanks Damian, Randal, Uri, Anonymmous, and others) does a fair job of highlighting Perl source code and has an auto-bounce-on-the-%-key feature that shows were the closing character matches up. Add that to a perl-tidy() run every week or so, and I have a reasonably easy tool chain I can use to enforce my coding style.

The important thing to remember is that "Coding Style" is a convention used to make your code easier for the Maintenance Programmer to understand. There is no one 'Holy and Sacred Way'; no Tao.

Like text editor choice, Style is good for discussions over Beer, but there is no one-true-way. (Rudyard Kipling said it better than I can -- "There are nine and sixty ways of constructing Tribal Lays, and every single one of them is right!", from 'In the Neolithic Age')

The worst thing you can do is *not* to have a consistent style. Pick a style of bracing and indentation that works for the way you feel comfortable writing your code a stick with it. Set up your editor of choice to produce that style and build a perl-tidy() configuration to regenerate code in that style. The MP will thank you for it. (And, there is nothing more embarrassing than picking a five-year-old piece of crufty old code, discovering that the coding style is "HidJe-ous! The indenting is inconsistent, and the bracing is **all** wrong!!", and then realizing who wrote it....)

----
I Go Back to Sleep, Now.

OGB

  • Comment on Re: Different ways of formatting/writing code

Replies are listed 'Best First'.
Re^2: Different ways of formatting/writing code
by FunkyMonk (Bishop) on Dec 09, 2009 at 23:56 UTC
    Style is good for discussions over Beer
    You want to add alcohol to a holy war? Sounds like poor advice to me:-)

    I think the most important thing is to pick a style and stick to it religiously. Unless style is inflicted upon you, of course.

      I think the most important thing is to pick a style and stick to it religiously.

      I stick religiously to, and hotly defend, my personal standards—until someone convinces me that they've got better ones, at which point I adopt those with born-again passion and deride those who use the silly old convention.

      Just checking: It is true that, once you find the One True Way of indenting, good code writes itself, right?

        "I stick religiously to, and hotly defend, my personal standards—until someone convinces me that they've got better ones, at which point I adopt those with born-again passion and deride those who use the silly old convention."

        Be wary of change for change sake, nuances change often, but good style is enduring.