in reply to Re: Isolating DNA cont.
in thread Isolating DNA cont.

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

Replies are listed 'Best First'.
Re^3: Isolating DNA cont.
by hippo (Archbishop) on Dec 22, 2018 at 11:47 UTC
    Nowadays, without really having to think about it, I start sections of code like

    I literally don't have to think about it because my editor does it for me. It is worth the investment of getting to know your editor of choice so that such boilerplate can be automated away.

        I literally don't have to think about it because my editor does it for me.

      Sure -- and I could do the same, but I prefer to type it myself. That's a personal preference -- whatever makes you the most productive you, go right ahead and do that.

      For instance (he said, donning his fireproof suit), I prefer vim to emacs -- I'm always amazed at what a powerful tool emacs is, but I'm happy with the less powerful vim. I know enough about the command line arguments (o argument for horizontal split, O for my favourite layout, vertical split) and the in-editor arguments (^W ^R to rotate windows, ^W = to make them equal sizes, gq} to wrap things, marking a block and to have perltidy clean it up) to be productive.

      Alex / talexb / Toronto

      Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

      "I literally don't have to think about it because my editor does it for me."

      I suspect that's not strictly true. Wouldn't you need to set up some sort of macros, shortcuts, hotkeys, etc. and then activate them to get the boilerplate added to the code. I'd love an editor that just knows exactly what I wanted, without me having to think about it, and then just automatically adds the appropriate code; however, I don't think such a beast exists.

      "It is worth the investment of getting to know your editor of choice ..."

      I've been using vi (or related versions, e.g. vim) for over 30 years. I believe I know it well.

      "... so that such boilerplate can be automated away."

      Every construct for every (programming, markup, etc.) language I use? I don't think so. Muscle memory requires no actual thinking: I'm usually thinking about the code logic to be added whilst I automatically type the basic construct boilerplate (which, in general, is only of the order of about a dozen keystrokes or so).

      — Ken