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


In reply to Re: Different ways of formatting/writing code by Old_Gray_Bear
in thread Different ways of formatting/writing code by DreamT

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.