[Israel.pm] Tabs vs. Spaces

Mikhael Goikhman migo at homemail.com
Thu Jun 10 13:46:22 PDT 2004


On 10 Jun 2004 11:05:09 +0300, Jason Elbaum wrote:
> 
> We're not going to come to agreement here [...] Everything there is
> to say on tabs vs. spaces has already been said.

I don't think one may easily find a summary of the whole picture in
Google, so here is one. There are mostly 5 developer types:

  1) that use only initial tabs, one per level
  2) that use tabs for indentation and optional spaces for alignment
  3) that use tabs and spaces, and hardcode the tab size
  4) that use spaces only, and hardcode indention size
  5) that don't care, or use any mix, or just whatever the editor may do

The last group should simply be educated and is not interesting at all.
The first two groups provide the code readable and editable with any tab
size, just follow simple rules. The second two groups don't care about
other developers at all and just force their hardcoded indentation.

The "tabs are evil" people from the forth group are as irrational as the
third group. Their files are the largest, they hardcode the number of
spaces (2 or 4), they incorrectly claim "tab is always 8 spaces", and
they among two other groups insist that this code looks nice:

     my $seconds_to_the_next_weekend = diff_seconds_between(time(),
                                                            $weekend...

or even:

     my $seconds_to_the_next_weekend = diff_seconds_between(time(123 +
                                                                 456),
                                                            $weekend...

I think this code is horrible, this is what "smart" editors force on you.
When either the variable name or the function name is renamed, the whole
unstructured code becomes unaligned too.

If you ask me, write completely structured code and join the first group:

     my $seconds_to_the_next_weekend =
          diff_seconds_between(time(), $weekend...

Here 5 spaces mean actually one tab. Or, if you prefer:

     my $seconds_to_the_next_weekend = diff_seconds_between(
          time(), $weekend...

And if for some reason you like how the original code looks, join the
second group, it uses exactly one leading tab in all lines of the same
statement. Such "indentation with alignment" policy is used in many
projects.

Just like it is undesirable to use mixed tabs and spaces (case 3), there
is no any valid reason to use spaces-only too (case 4). Unless you count
a broken (hi, emacs) or non-configured editor as a reason.

Regards,
Mikhael.

-- 
perl -e 'print+chr(64+hex)for+split//,d9b815c07f9b8d1e'



More information about the Perl mailing list