G'day Alex,

++ I just wanted to add my agreement with, and recommendation of, this method of coding.

I started doing this many years ago — in fact, possibly a couple of decades ago — and it's made my (programming) life a whole lot easier.

Nowadays, without really having to think about it, I start sections of code like:

while (<$fh>) { }

or

if ($condition) { } else { }

I then don't have to remember to add closing braces. I also don't need to worry about aligning the closing braces to get the proper indentation: auto-indent has already done that for me.

The same works for other balanced characters. Building up a complex expression incrementally like this:

if () { if (is_whatever()) { if (is_whatever(get_whatever())) { if (is_whatever(get_whatever(get_options()))) {

almost never results in a "mis-matched parentheses" type error.

Attempting to type that final expression all at once, often will; and leaves you having to scan back and forth over the expression, counting opening and closing parentheses.

I also use this method for building up complex regular expressions (using the x or xx modifiers).

This may not work for everyone; for example, perhaps syntax-highlighting is set up to indicate mis-match problems. However, it certainly works for me and clearly works for you. I would recommend people at least try it.

— Ken


In reply to Re^2: Isolating DNA cont. by kcott
in thread Isolating DNA cont. by undergradguy

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.