in reply to Re: A Question of style.
in thread A Question of style.

It doesn't matter what style of indentation you use. As long as you use it consistently.

If by "consistently" you mean "always the same way", then I actually disagree with this, at least to some extent. It is my considered opinion that good indentation style takes into consideration the semantics of the code being indented. Sometimes I put up to three "statements" (things between semi-colons) on the same line, if what they are doing is sufficiently related that it enhances, rather than impedes clarity, and indeed, that can make a block rather compact...

if (condition) { $foo=0; $bar++; }

But I certainly wouldn't recommend doing *all* conditional blocks that way. Also, sometimes I put something after a closing brace, on the same line, but only if what it's doing is related to the closing of the block, as in...

open FOO, '<', $filename; while (<FOO>) { chomp; my ($bar, $baz, $quux) = $_ =~ /someregex/; push @quux, [$foo, $baz, $quux] if $quux; } close FOO;

But again, I certainly wouldn't recommend always putting code on the same line after the closing brace. If it weren't logically related to the closing of the block, that could get very confusing. If I had to distill this to a general principle, it would be, take the code's semantics into consideration when deciding how much whitespace to use and where to use it.


"In adjectives, with the addition of inflectional endings, a changeable long vowel (Qamets or Tsere) in an open, propretonic syllable will reduce to Vocal Shewa. This type of change occurs when the open, pretonic syllable of the masculine singular adjective becomes propretonic with the addition of inflectional endings."  — Pratico & Van Pelt, BBHG, p68

Replies are listed 'Best First'.
Re^2: A Question of style.
by Nkuvu (Priest) on Jun 07, 2005 at 16:24 UTC
    No, I don't mean "always the same way." I'm talking about avoiding inconsistent indentation style like:
    if (condition) { code; other_code; } else { bork; } if (condition_2) { foo; } else { i_think_you_get_what_i_mean(); }
    I don't peronsally mind if a block is on one line, as long as it's short. if (condition) { $foo=0; $bar++; } is perfectly fine. I mean consistency within a file, given the context. If you always put short blocks on one line, great. If you do something like
    if (condition) { $foo=0; $bar++ } # more code... if (other_condition) { $foo++; }
    then I consider it to be inconsistent. And when I find inconsistent indentation it implies to me that your thinking isn't clear. This may or may not be the case -- it's more of an impression I get than an absolute rule.