[Wellington-pm] My new indentation technique is unstoppable!!

Sam Vilain sam at vilain.net
Thu Aug 14 18:52:13 PDT 2008


Indenting techniques are an old flamewar ground.  Until recently I just
used cperl-mode's default settings in emacs, and had once read RMS'
style guidelines and left it at that.

However recently working with some code from the git project (which uses
the Linux kernel style), I saw some of the virtue of using tabs,
especially over "I choose" indenting styles like space-only or "screw
your tab width setting" styles like the mixed-spaces/tabs one that is
default in emacs.

 - to be friendly to people who prefer different indent levels, use real
   tabs and not spaces to indent

 - a single tab per indent is OK, but never use them to line up lines,
   eg:

   if (blah &&
   ␠␠␠␠blahblah) {
   }

   Because the second part of the if should line up three characters
   along, it should be indented with spaces and not tabs.

 - avoid constructs which require lots of space indenting, and keep the
   last comma in lists and the closing bracket on a new line:

   eg, not
     Object->new( param => foo,
     ␠␠␠␠␠␠␠␠␠␠␠␠␠param => bar);
     function(arg, arg, arg,
     ␠␠␠␠␠␠␠␠␠arg, arg);
   but:
     Object->new
     → ( param => foo,
     → ␠␠param => bar,
     → );
     function
     → ( arg, arg, arg,
     → ␠␠arg, arg,
       );

    this is the sort of thing that leads to easy mergability of code,
    because the logical parts of the function call are all on seperate
    lines, and to add a list item you can just insert a line.

I don't think perltidy will do all of the above nicely, but this is
pretty close:

 perltidy \
        --maximum-line-length=78 \
        --tabs \
        --closing-token-indentation=1 \
        --delete-closing-side-comments \
        filename

If you want to see how it works out in practice, take a look at some of
my recent work, like IO::Plumbing on CPAN or VCS::Git::Torrent (clone
git://utsl.gen.nz/VCS-Git-Torrent).

Sam


More information about the Wellington-pm mailing list