For level of indentation: 8 is popular in C. Java style guidelines mostly follow K&R, but specify a level-4 indent. The reason is that Java identifiers tend to be very long, and that if you are strict about indenting braces, you end up with a lot of levels of indentation before you get to any real code (one level for the class block, one for your method, and another for a try, which any non-trivial code will need). Perl is closer to C than Java, so I usually use 8, but I wouldn't be surprised to see many experianced Perl programmers use 4.
How to deal with people who don't use the same tabstop as you do is a problem. You could set it to output spaces instead of a literal \t, but I don't like having to do 8x or 4x to remove a level of indentation (in vi) when I can use simple x instead. Further, I like the level of indentation to show up exactly the number of spaces I have my editor set to. At the same time, I must remember that otehr people also want it to look right with different tab settings. I must respect their settings if I expect them to respect mine.
This code shouldn't have a problem with anyones' settings:
sub foo { <TAB>my ($bar, $baz) = @_; <TAB>if($bar) { <TAB><TAB>return $baz; <TAB>} <TAB>return 0; }
If I have tabstop set to 8 and someone else has it set to 4, it will look right in both cases. However, this code might not:
sub foo { <TAB>my %hash = ( <TAB><TAB>bar<TAB>=> 1, <TAB><TAB>baz<TAB>=> 1, <TAB>); <TAB>return %hash; }
The tab embedded in the hash syntax could end up at very different places. In the specifc example above, it probably won't be an issue. It would be an issue where one of the hash keys was particularly longer than the other. Instead of this:
my %hash = ( foo => 1, longer_key => 1, );
Someone with a shorter tab stop might see this:
my %hash = ( foo => 1, longer_key => 1, );
The solution I've found is to tab at the beginning levels of indentation for the block, but to put spaces in internal indentation. For example:
<TAB>foo<SP><SP><SP><SP><SP><SP><SP><SP>=> 1, <TAB>longer_key<SP>=> 1,
(It doesn't line up above, but it should if you replace each <SP> with a real space).
There are still a few situations where this won't work, but I think it's as close to making everyone happy as we can get. Except for Abigail-II, who isn't happy about anything :)
----
: () { :|:& };:
Note: All code is untested, unless otherwise stated
In reply to Re: The classical <TAB> issue
by hardburn
in thread The classical TAB issue
by Lorand
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |