in reply to A Question of style.

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

Replies are listed 'Best First'.
Re^2: A Question of style.
by jhourcle (Prior) on Jun 07, 2005 at 03:58 UTC

    By that argument, would lack of indentation qualify as consistent use?

    Personally, I use what makes sense to me. I never focused on a particular style until I learned to write LPC, and I still write my Perl that way. (trust me -- it's better than how I learned to format Perl, as I came from a BASIC, Logo, Pascal and FORTRAN before that).

    As things go, I think that screen size and editor choice play a rather significant role in what someone's preferred style. Someone who learned to program on a 12 line high screen, or through a dumb terminal is going to think differently than someone who started programming with a 21" monitor on their desk. Likewise, someone who started out in ex/ed, or some other line editor is going to work much different from someone who worked in DOS EDIT, or BBEdit, or whatever else the popular editors are these days.

    I'm personally okay with just about anything, because I'll just reflow it. (which works up until I'm trying to submit patches, in which case I have to save my initial reformatted version, so I can diff that and the final, then re-apply the changes with the author's style of formatting back to the original. For the most part, I'm happy with whatever I'm given -- it's normally enough for me that people have gone out of their way to give their code at all, I'm not going to be overly picky about how many spaces are in it.

Re: A Question of style.
by jonadab (Parson) on Jun 07, 2005 at 11:09 UTC
    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
      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.