Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Keep It Simple, Stupid
 
PerlMonks  

Re: The One True Style of indentation:

by japhy (Canon)
on Apr 14, 2002 at 17:11 UTC ( #158956=note: print w/ replies, xml ) Need Help??


in reply to The One True Style of indentation:

It's so sad to see so many people answering incorrectly here. It's TWO spaces. I don't want to have to tell you guys again.

<newPerlOrder>You will use two spaces per level to indent your code. You will write one-lined 'if's when possible. You will leave space in between 'if', the parenthesized expression, and the block. The opening brace will appear on the same line as the 'if'. There will be no cuddled 'else's. Here is the One True Way. Praise japhy for showing it.

if (condition) { # stuff # and more stuff } elsif (condition) { really-short-stuff } else { # ok }
</newPerlOrder>

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a (from-home) job
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;


Comment on Re: The One True Style of indentation:
Select or Download Code
Re: Re: The One True Style of indentation:
by Dog and Pony (Priest) on Apr 14, 2002 at 17:20 UTC
    Dog and Pony quickly forms an underground guerilla to combat this new Perl order... "We will fight you to the end, evil unbelieving two-spacer! Don't touch our holy braces!"

    :)


    You have moved into a dark place.
    It is pitch black. You are likely to be eaten by a grue.
Re: Re: The One True Style of indentation:
by Parham (Friar) on Apr 14, 2002 at 19:28 UTC
    i do it exactly how japhy does it. I'm a "two-spacer" because it's neither too much, or too little (damn that "one-space" indentation). If i'm drunk, acting drunk, or feeling drunk, i'd like to think i'm a "All on one big line" person ;)
Re: Re: The One True Style of indentation:
by brianarn (Chaplain) on Apr 16, 2002 at 01:28 UTC
    <signs up for the newPerlOrder>
    Viva la order! Two spaces for everyone!

    ~Brian
Re: Re: The One True Style of indentation:
by Adze (Acolyte) on Apr 16, 2002 at 17:14 UTC
Re: Re: The One True Style of indentation:
by pdcawley (Hermit) on Apr 17, 2002 at 08:23 UTC
    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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (10)
As of 2014-04-18 13:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (468 votes), past polls