Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Re: The One True Style of indentation:

by pdcawley (Hermit)
on Apr 17, 2002 at 08:23 UTC ( #159746=note: print w/ replies, xml ) Need Help??


in reply to Re: The One True Style of indentation:
in thread The One True Style of indentation:

It's weird, I normally go with four spaces in personal code, but in my recent Perl6 'apocryphal' SchemeInterpreter I switched over to two spaces and I'm surprised by how much I like it.

Then again, this is code that I'll likely be using as the basis for an pod file discussing how it works and what's changed since Perl 6, so horizontal space is precious.

All that said, I'll use whatever the prevailing style is at whatever site I'm working on. If there is no prevailing style then I'll work to get one established and will argue for my choices, but once consensus is reached I go with that. The one thing I will not stand for is tabs used for anything but 'basic' indentation. For instance, consider the following (not good style, but it's just here to illustrate a point) code:

sub double_dispatch { my $self = shift; my $arg = shift; $arg->method($self, args => [@_]); }
If tabs are used for indentation then the 'actual characters' used would be as follows. Take '>>>>' to equal one tab.
sub double_dispatch { >>>>my $self = shift; >>>>my $arg = shift; >>>>$arg->method($self, >>>> args => [@_]); }
Using 'hard' tabs to do 'alignment' formatting is Bad And Wrong; it embeds your assumptions about tab width into the source file thus defeating the purpose of using tabs in the first place. Don't do it people.

I would be much more sanguine about tab indented code if people stuck to this rule, but unfortunately, they don't. Even more depressingly, the likes of emacs's otherwise wonderful cperl-mode doesn't make the distinction either. So for now, I argue for 'indents shall be a fixed number of spaces per level'. All things being equal, I choose four.

Yes, your assumptions are embedded in the source this way, but at least your careful formatting doesn't get fscked over when someone chooses a different tab width to view it with.


Comment on Re: Re: The One True Style of indentation:
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://159746]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (14)
As of 2014-12-18 20:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (61 votes), past polls