You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@spamassassin.apache.org by Sidney Markowitz <si...@sidney.com> on 2004/02/09 22:23:06 UTC

What are the official source file indentation standards?

Can someone tell me or point me to the indentation standards for the 
perl source files in SpamAssassin? Use tab characters, or only spaces, 
or it doesn't matter? If tabs are used what tab width? And indent by how 
much? I'm having difficulty distinguishing standards from what may be 
mistakes or simply lack of standards in some source files.

If any of you use emacs and have set up the right options in their 
~/.emacs file for perl-mode, seeing what they are would make it easy for me.

Thanks,

  -- sidney


Re: What are the official source file indentation standards?

Posted by Daniel Quinlan <qu...@pathname.com>.
Duncan Findlay <du...@debian.org> writes:

> Sounds good. I was a little unsure about the tightness bit, but 2
> looks appropriate from the manpage. I might add -lp and/or -icp

-lp yes
-icp no
 
> Do we want to go ahead and start using perltidy?

Not yet!  We have to agree on what the parameters "are" and (assuming we
might opt to add a few standards) should be.

Daniel

-- 
Daniel Quinlan                     anti-spam (SpamAssassin), Linux,
http://www.pathname.com/~quinlan/    and open source consulting

Re: What are the official source file indentation standards?

Posted by Duncan Findlay <du...@debian.org>.
On Mon, Feb 09, 2004 at 04:19:57PM -0600, Bob Apthorpe wrote:
> Is this a reasonable set of defaults for perltidy?

At some point, using perltidy might be a good idea... we have never
really worried about style.
 
> # perltidyrc
>  -i=2    # use n columns per indentation level (default n=4)
>  -nt     # no tabs: use n spaces per indentation level (default)
>  -bt=2   # sets brace tightness,  n= (0 = loose, 1=default, 2 = tight)
>  -pt=2   # paren tightness (n=0, 1 or 2)
>  -sbt=2  # square bracket tightness (n=0, 1, or 2)
>  -ce     # cuddled else; use this style: '} else {'
>  -bar    # opening brace always on right, even for long clauses

I'm not sure about -bar

> # __END__
> 
> -- Bob
> 

Sounds good. I was a little unsure about the tightness bit, but 2
looks appropriate from the manpage. I might add -lp and/or -icp

Do we want to go ahead and start using perltidy?

-- 
Duncan Findlay

Re: What are the official source file indentation standards?

Posted by Theo Van Dinter <fe...@kluge.net>.
On Tue, Feb 10, 2004 at 12:57:45PM -0800, Dan Quinlan wrote:
> PLEASE WAIT until we agree on the exact parameters.  I only want to run
> perltidy once!

Well, if we come up with the standard, we'd want to run it periodically
to make sure the code is all done up correctly.

But yeah, let's "measure twice, cut once", so to speak.

-- 
Randomly Generated Tagline:
"You just reciprocate the small one ..."      - Peter Sagerson

Re: What are the official source file indentation standards?

Posted by "Malte S. Stretz" <ms...@gmx.net>.
On Tuesday 10 February 2004 21:57 CET Daniel Quinlan wrote:
> Justin Mason <jm...@jmason.org> writes:
> >   - go crazy with perltidy if you like ;)  it's about the right time in
> >     the dev timeline to do so.
>
> -1
>
> PLEASE WAIT until we agree on the exact parameters.  I only want to run
> perltidy once!

And until all outstanding patches are applied! I have three old ones 
lingering around, will apply them tomorrow.

Cheers,
Malte

-- 
[SGT] Simon G. Tatham: "How to Report Bugs Effectively"
      <http://www.chiark.greenend.org.uk/~sgtatham/bugs.html>
[ESR] Eric S. Raymond: "How To Ask Questions The Smart Way"
      <http://www.catb.org/~esr/faqs/smart-questions.html>

Re: What are the official source file indentation standards?

Posted by Daniel Quinlan <qu...@pathname.com>.
Justin Mason <jm...@jmason.org> writes:

>   - go crazy with perltidy if you like ;)  it's about the right time in
>     the dev timeline to do so.

-1

PLEASE WAIT until we agree on the exact parameters.  I only want to run
perltidy once!

Daniel

-- 
Daniel Quinlan                     anti-spam (SpamAssassin), Linux,
http://www.pathname.com/~quinlan/    and open source consulting

Re: What are the official source file indentation standards?

Posted by Daniel Quinlan <qu...@pathname.com>.
Duncan Findlay <du...@debian.org> writes:

> Why? Personally, I like the cuddled else. It's so nice and pretty and
> cuddly :-)

I hate cuddled else.  It makes the code less readable for the sake of
saving a line.

Daniel

-- 
Daniel Quinlan                     anti-spam (SpamAssassin), Linux,
http://www.pathname.com/~quinlan/    and open source consulting

Re: What are the official source file indentation standards?

Posted by Duncan Findlay <du...@debian.org>.
On Mon, Feb 09, 2004 at 05:39:54PM -0500, Theo Van Dinter wrote:
> On Mon, Feb 09, 2004 at 04:19:57PM -0600, Bob Apthorpe wrote:
> > Is this a reasonable set of defaults for perltidy?
> 
> excellent, another perltidy user! :)
> 
> > # perltidyrc
> >  -i=2    # use n columns per indentation level (default n=4)
> 
> That's all I use normally, but ...
> 
> >  -ce     # cuddled else; use this style: '} else {'
> 
> IMO this should be frowned upon.

Why? Personally, I like the cuddled else. It's so nice and pretty and
cuddly :-)

-- 
Duncan Findlay

Re: What are the official source file indentation standards?

Posted by Theo Van Dinter <fe...@kluge.net>.
On Mon, Feb 09, 2004 at 04:19:57PM -0600, Bob Apthorpe wrote:
> Is this a reasonable set of defaults for perltidy?

excellent, another perltidy user! :)

> # perltidyrc
>  -i=2    # use n columns per indentation level (default n=4)

That's all I use normally, but ...

>  -ce     # cuddled else; use this style: '} else {'

IMO this should be frowned upon.

The rest look fine at a cursory glance.

-- 
Randomly Generated Tagline:
"4) Bobby Flay is coming to your house to tape an episode of "Food Nation"
 so you thoughtfully replace your 'Welcome' mat with a large wooden
 cutting board."
         - From the Top 12 Signs You've Been Watching Too Much FoodTV

Re: What are the official source file indentation standards?

Posted by Bob Apthorpe <ap...@cynistar.net>.
Hi,

On Mon, 9 Feb 2004, Theo Van Dinter wrote:

> On Tue, Feb 10, 2004 at 10:23:06AM +1300, Sidney Markowitz wrote:
> > Can someone tell me or point me to the indentation standards for the
> > perl source files in SpamAssassin? Use tab characters, or only spaces,
> > or it doesn't matter? If tabs are used what tab width? And indent by how
> > much? I'm having difficulty distinguishing standards from what may be
> > mistakes or simply lack of standards in some source files.
>
> I don't think we ever came up with an "official" set of standards.  In
> general:
>
> - indents are 2 spaces
> - use 'if (expr) {', although 'if ( expr ) {' is tolerated when I do it. ;)
>
> uhh...  that's all I can remember.

Is this a reasonable set of defaults for perltidy?

# perltidyrc
 -i=2    # use n columns per indentation level (default n=4)
 -nt     # no tabs: use n spaces per indentation level (default)
 -bt=2   # sets brace tightness,  n= (0 = loose, 1=default, 2 = tight)
 -pt=2   # paren tightness (n=0, 1 or 2)
 -sbt=2  # square bracket tightness (n=0, 1, or 2)
 -ce     # cuddled else; use this style: '} else {'
 -bar    # opening brace always on right, even for long clauses
# __END__

-- Bob

Re: What are the official source file indentation standards?

Posted by Duncan Findlay <du...@debian.org>.
On Tue, Feb 10, 2004 at 12:45:44PM -0800, Daniel Quinlan wrote:
> Theo Van Dinter <fe...@kluge.net> writes:
> 
> > I don't think we ever came up with an "official" set of standards.  In
> > general:
> > 
> > - indents are 2 spaces
> > - use 'if (expr) {', although 'if ( expr ) {' is tolerated when I do it. ;)
> > 
> > uhh...  that's all I can remember.
> 
> We generally (about 54-59% of our perl code) collapse each set of 8
> leading spaces into a tab.

We do... but do we want to continue doing so? I'd vote for spaces.

> > # perltidyrc
> >  -i=2    # use n columns per indentation level (default n=4)
> 
> Yes, although I think 4 would be better.

I'm indifferent.
 
> >  -nt     # no tabs: use n spaces per indentation level (default)
> 
> Not quite, see above.

I'm going to vote for -nt.

> >  -ce     # cuddled else; use this style: '} else {'
> 
> Disagreement on this one.  I think Justin does this, but nobody else
> does.

Well, I do... but I guess I can stop, if everyone agrees this is
bad...

-- 
Duncan Findlay

Re: What are the official source file indentation standards?

Posted by "Malte S. Stretz" <ms...@gmx.net>.
On Wednesday 11 February 2004 00:42 CET Daniel Quinlan wrote:
> "Malte S. Stretz" <ms...@gmx.net> writes:
> > Uh, no, please not. That's one thing I always "fix" when I see it (I
> > never had the idea this might be intentional -- to me it was just some
> > annoying behaviour of some editors, incuding vim). Either always use
> > tabs or always use two spaces, but don't mix-and-match.
>
> Mix-and-match, yes!
>
> *Some* editors?  It's *both* emacs and vim and it's done as a default in
> those because it makes navigation easier. 

Huh? I can't see any way how \t\s\s\s\s for a 12er-indentation makes 
navigation easier. In my eyes it makes it even *worse*: I hate it when I'm 
on column 2 and move down the curser and it starts to jump around wildly.

> Representing 32 consecutive columns as spaces is annoying.  

Why? What the hell is annoying about this?

> To turn around Kenneth's argument, in 
> this day and age when every editor can handle tabs very well, is there
> any reason to use spaces slavishly for columns?

As I said in the first place, I don't really care if it is two spaces or 
tabs. I've been heavily on the spaces camp back in time, but if folks want 
to use tabs that's ok with me.

But *don't* mix it, ie. replace every eight spaces with tabs. That is always 
inconsistent because every editor does it differently and what's even 
worse, it makes changing indentations a PITA, eg. if you have to outdent an 
eighter-spaces-block into a sixer. Plus other annoyances I can't remember 
currently but which bit me when I edited such code.

> > You mean a newline before the curly brace? I think the rule of thumb is
> > to do so for subs and big blocks, short blocks may have the curly on
> > the same line.
>
> No, just after the first set of declarations.

Ah, ok, I thought you meant the newline before the brace, so

> sub foo {

sub foo
{

> > Please not 4. Either two or tabs, everything else is a pain in the
> > thumb to code with when you don't have a good editor around.
>
> What, are you using edlin or something?

No, vim and KWrite. Sometimes also nano and vi, depends on the system I'm 
on. But even in vim you sometimes have to correct the indentation manually 
(actually do I often ':set noai' when vim again annoys the hell out of me).

> > All the three above should be the same, either 1 or 2, I'd prefer 1.
>
> Why the same?  They are separate options for a reason.  1,2,2 I think.

But the rationale is the same for all three of them. As I know myself, will 
I probably continue to code in 2,2,2, but 1,1,1 should be more readable :) 
I don't really care about this.

> > -sbl :)
>
> Yeah, you lose this one.  :-)

I'm fine with anything but -bli and -icb. And mixing tabs and spaces ;-)

Cheers,
Malte

-- 
[SGT] Simon G. Tatham: "How to Report Bugs Effectively"
      <http://www.chiark.greenend.org.uk/~sgtatham/bugs.html>
[ESR] Eric S. Raymond: "How To Ask Questions The Smart Way"
      <http://www.catb.org/~esr/faqs/smart-questions.html>

Re: What are the official source file indentation standards?

Posted by Kenneth Porter <sh...@sewingwitch.com>.
--On Tuesday, February 10, 2004 4:34 PM -0800 Kenneth Porter 
<sh...@sewingwitch.com> wrote:

> It's not a matter of whether they handle tabs well, but whether they
> handle them consistently.

I googled for "tabs versus spaces indenting" and got lots of hits. I like 
this one:

<http://www.jwz.org/doc/tabs-vs-spaces.html>

Re: What are the official source file indentation standards?

Posted by Daniel Quinlan <qu...@pathname.com>.
Kenneth Porter <sh...@sewingwitch.com> writes:

> I recall also a rule of thumb that one should not optimize code 
> prematurely. Before making a cost argument, it would be useful to see what 
> percentage of the source code is white space and how much of a savings 
> would occur if runs of spaces were converted to equivalent 8-column tabs. 
> I'd guess that it's comparable to the space wasted in the "slack" space at 
> the end of a file's last sector. Does anyone care enough about that issue 
> to do the analysis?

This is a really silly strawman.  It's not at all about saving bytes.

Daniel

-- 
Daniel Quinlan                     anti-spam (SpamAssassin), Linux,
http://www.pathname.com/~quinlan/    and open source consulting

Re: What are the official source file indentation standards?

Posted by Kenneth Porter <sh...@sewingwitch.com>.
--On Tuesday, February 10, 2004 3:42 PM -0800 Daniel Quinlan 
<qu...@pathname.com> wrote:

> Representing 32 consecutive columns as spaces is annoying.

I'm a little unclear on why that's so. If I'm moving the cursor vertically 
through code, I don't want it jumping around as it passes through white 
space. If I'm moving horizontally, I generally use emacs by-word 
operations, not character keys, so the makeup of white space is irrelevant.

What kind of navigation are you doing that makes runs of spaces annoying?

> To turn around Kenneth's argument, in this day and age when every editor
> can handle tabs very well, is there any reason to use spaces slavishly
> for columns?

It's not a matter of whether they handle tabs well, but whether they handle 
them consistently.

I recall also a rule of thumb that one should not optimize code 
prematurely. Before making a cost argument, it would be useful to see what 
percentage of the source code is white space and how much of a savings 
would occur if runs of spaces were converted to equivalent 8-column tabs. 
I'd guess that it's comparable to the space wasted in the "slack" space at 
the end of a file's last sector. Does anyone care enough about that issue 
to do the analysis?

Re: What are the official source file indentation standards?

Posted by Sidney Markowitz <si...@sidney.com>.
Daniel Quinlan wrote:
> *Some* editors?  It's *both* emacs and vim and it's done as a default in
> those because it makes navigation easier.  Representing 32 consecutive
> columns as spaces is annoying.  To turn around Kenneth's argument, in
> this day and age when every editor can handle tabs very well, is there
> any reason to use spaces slavishly for columns?

Every reasonable editor can handle tabs fine and set 8 columns as 
default, but every reasonable editor lets you change the default, and 
every programmer has their own preference.

Tab width is the one issue that I have never seen resolved when trying 
to come up with consensus coding standards in a development team. The 
only solution that works is to have source files use all spaces and no 
tab characters. Another possible solution is for the developers to use 
one editor or editor configuration for editing source files for the 
project, and a different editor or editor configuration for whatever 
else it is that they do in which they are used to their own tab setting.

If you push it I suppose I could figure out how to set tab width in 
emacs local to perl-mode. I don't know if vi users can do that. If they 
can't it would be very annoying for their editor to have the "wrong" tab 
width. Setting perl indentation to 2 vs 4 is much less of a problem to 
general use of the editor.

  -- sidney


Re: What are the official source file indentation standards?

Posted by Daniel Quinlan <qu...@pathname.com>.
"Malte S. Stretz" <ms...@gmx.net> writes:

> Uh, no, please not. That's one thing I always "fix" when I see it (I never 
> had the idea this might be intentional -- to me it was just some annoying 
> behaviour of some editors, incuding vim). Either always use tabs or always 
> use two spaces, but don't mix-and-match.

Mix-and-match, yes!

*Some* editors?  It's *both* emacs and vim and it's done as a default in
those because it makes navigation easier.  Representing 32 consecutive
columns as spaces is annoying.  To turn around Kenneth's argument, in
this day and age when every editor can handle tabs very well, is there
any reason to use spaces slavishly for columns?
 
> You mean a newline before the curly brace? I think the rule of thumb is to 
> do so for subs and big blocks, short blocks may have the curly on the same 
> line.

No, just after the first set of declarations.

sub foo {
  my ($self, $bar) = @_;

  code_here;
}
 
> Please not 4. Either two or tabs, everything else is a pain in the thumb to 
> code with when you don't have a good editor around.

What, are you using edlin or something?
 
> All the three above should be the same, either 1 or 2, I'd prefer 1.

Why the same?  They are separate options for a reason.  1,2,2 I think.
 
> -sbl :)

Yeah, you lose this one.  :-)

Daniel

-- 
Daniel Quinlan                     anti-spam (SpamAssassin), Linux,
http://www.pathname.com/~quinlan/    and open source consulting

Re: What are the official source file indentation standards?

Posted by "Malte S. Stretz" <ms...@gmx.net>.
On Tuesday 10 February 2004 21:45 CET Daniel Quinlan wrote:
> Theo Van Dinter <fe...@kluge.net> writes:
> > I don't think we ever came up with an "official" set of standards.  In
> > general:
> >
> > - indents are 2 spaces
> > - use 'if (expr) {', although 'if ( expr ) {' is tolerated when I do
> > it. ;)
> >
> > uhh...  that's all I can remember.
>
> We generally (about 54-59% of our perl code) collapse each set of 8
> leading spaces into a tab.

Uh, no, please not. That's one thing I always "fix" when I see it (I never 
had the idea this might be intentional -- to me it was just some annoying 
behaviour of some editors, incuding vim). Either always use tabs or always 
use two spaces, but don't mix-and-match.

> Blank line after initial declarations of a sub.  Blank lines in rest of
> sub are optional.

You mean a newline before the curly brace? I think the rule of thumb is to 
do so for subs and big blocks, short blocks may have the curly on the same 
line.

> I agree about not using cuddled else, but I don't think we should start
> using spaces around if and while expressions.  I don't know when that
> started, but it's really annoying.

I think there must have been some BSD C coder a round who introduced that :) 
They use spaces after keywords but not after function calls. 

> Also note that 80 columns is our width.  It's okay to exceed that on
> rare occasions where it is necessary or looks much better, but it's
> generally better to go on to the next line.
>
> Bob Apthorpe <ap...@cynistar.net> writes:
> > # perltidyrc
> >  -i=2    # use n columns per indentation level (default n=4)
>
> Yes, although I think 4 would be better.

Please not 4. Either two or tabs, everything else is a pain in the thumb to 
code with when you don't have a good editor around.

> >  -nt     # no tabs: use n spaces per indentation level (default)
>
> Not quite, see above.

See above :)

> >  -bt=2   # sets brace tightness,  n= (0 = loose, 1=default, 2 = tight)
>
> I think we use 1?

We use both, I think 1 is preferrable.

> >  -pt=2   # paren tightness (n=0, 1 or 2)
>
> definitely 2.
>
> >  -sbt=2  # square bracket tightness (n=0, 1, or 2)
>
> definitely 2.

All the three above should be the same, either 1 or 2, I'd prefer 1.

> >  -ce     # cuddled else; use this style: '} else {'
>
> Disagreement on this one.  I think Justin does this, but nobody else
> does.

ACK. I do it sometimes when I have an if-then-else with just a few lines in 
the blocks, but for large blocks hard to read.

> >  -bar    # opening brace always on right, even for long clauses
>
> I think -nbl is closer.

-sbl :)

Cheers,
Malte

-- 
[SGT] Simon G. Tatham: "How to Report Bugs Effectively"
      <http://www.chiark.greenend.org.uk/~sgtatham/bugs.html>
[ESR] Eric S. Raymond: "How To Ask Questions The Smart Way"
      <http://www.catb.org/~esr/faqs/smart-questions.html>

Re: What are the official source file indentation standards?

Posted by Theo Van Dinter <fe...@kluge.net>.
On Tue, Feb 10, 2004 at 12:45:44PM -0800, Dan Quinlan wrote:
> I agree about not using cuddled else, but I don't think we should start
> using spaces around if and while expressions.  I don't know when that
> started, but it's really annoying.

That probably started when I started coding since that's been my style
for years.  I may be the only one doing it too, I haven't really paid
attention.

-- 
Randomly Generated Tagline:
Bart:	Dad, you killed the Zombie Flanders!
 
 Homer:	He was a zombie?
 
 		   Treehouse of Horror III

Re: What are the official source file indentation standards?

Posted by Daniel Quinlan <qu...@pathname.com>.
Theo Van Dinter <fe...@kluge.net> writes:

> I don't think we ever came up with an "official" set of standards.  In
> general:
> 
> - indents are 2 spaces
> - use 'if (expr) {', although 'if ( expr ) {' is tolerated when I do it. ;)
> 
> uhh...  that's all I can remember.

We generally (about 54-59% of our perl code) collapse each set of 8
leading spaces into a tab.

Blank line after initial declarations of a sub.  Blank lines in rest of
sub are optional.

I agree about not using cuddled else, but I don't think we should start
using spaces around if and while expressions.  I don't know when that
started, but it's really annoying.

Also note that 80 columns is our width.  It's okay to exceed that on
rare occasions where it is necessary or looks much better, but it's
generally better to go on to the next line.

Bob Apthorpe <ap...@cynistar.net> writes:

> # perltidyrc
>  -i=2    # use n columns per indentation level (default n=4)

Yes, although I think 4 would be better.

>  -nt     # no tabs: use n spaces per indentation level (default)

Not quite, see above.

>  -bt=2   # sets brace tightness,  n= (0 = loose, 1=default, 2 = tight)

I think we use 1?

>  -pt=2   # paren tightness (n=0, 1 or 2)

definitely 2.

>  -sbt=2  # square bracket tightness (n=0, 1, or 2)

definitely 2.

>  -ce     # cuddled else; use this style: '} else {'

Disagreement on this one.  I think Justin does this, but nobody else
does.

>  -bar    # opening brace always on right, even for long clauses

I think -nbl is closer.

Daniel

-- 
Daniel Quinlan                     anti-spam (SpamAssassin), Linux,
http://www.pathname.com/~quinlan/    and open source consulting

Re: What are the official source file indentation standards?

Posted by Theo Van Dinter <fe...@kluge.net>.
On Tue, Feb 10, 2004 at 10:23:06AM +1300, Sidney Markowitz wrote:
> Can someone tell me or point me to the indentation standards for the 
> perl source files in SpamAssassin? Use tab characters, or only spaces, 
> or it doesn't matter? If tabs are used what tab width? And indent by how 
> much? I'm having difficulty distinguishing standards from what may be 
> mistakes or simply lack of standards in some source files.

I don't think we ever came up with an "official" set of standards.  In general:

- indents are 2 spaces
- use 'if (expr) {', although 'if ( expr ) {' is tolerated when I do it. ;)

uhh...  that's all I can remember.

-- 
Randomly Generated Tagline:
"All language designers are arrogant.  Goes with the territory..."
 (By Larry Wall)