indentation

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Mon Oct 20 21:42:57 EDT 2008


On Mon, 20 Oct 2008 18:55:46 -0400, J. Clifford Dyer wrote:

> On Mon, 2008-10-20 at 13:29 +0000, Steven D'Aprano wrote:
>> On Mon, 20 Oct 2008 11:01:19 +0200, Bruno Desthuilliers wrote:
>> 
>> > Steven D'Aprano a écrit :
>> >> On Sun, 19 Oct 2008 19:03:29 +0200, Bruno Desthuilliers wrote:
>> >> 
>> >>> Steven D'Aprano a écrit :
>> >>>
>> >>> (snip)
>> >>>
>> >>>> You can use tabs, or spaces. If you use spaces, you can choose 4
>> >>>> spaces, or 8, or any number,
>> >>> By all means, make it 4 spaces - that's the standard.
>> >> 
>> >> It's *a* standard. I believe it is the standard for the Python
>> >> standard library, but there are other standards.
>> > 
>> > I can't remember having seen any other "standard" so far.
>> 
>> 
>> How about PEP 8? It's not even hidden deep in the bowels of the PEP --
>> it's almost at the top.
>> http://www.python.org/dev/peps/pep-0008/
>> 
>> "For really old code that you don't want to mess up, you can continue
>> to use 8-space tabs."
>> 
>> 
> Fair, but limited to old code, so doesn't apply to instructions for new
> code.

I didn't say it does. But it's a standard, one of many.


>> Then there's string.expandtabs():
>> 
>> expandtabs(...)
>>     S.expandtabs([tabsize]) -> string
>> 
>>     Return a copy of S where all tab characters are expanded using
>>     spaces. If tabsize is not given, a tab size of 8 characters is
>>     assumed.
>> 
>> 
> The default for a tab does not imply anything about how python code
> should be indented.

But it implies that 8 spaces is a standard.


[snip]
> Not python.  I think when Bruno says it's *the* standard, we can assume
> he means "for python."

When you make an assumption, you make an ASS out of U and MPTION.

*wink*

I didn't think my post was terribly difficult to understand or that it 
would be so controversial. It is a simple objective fact that there is no 
such "THE" standard, not even for Python. Certainly it is true that 4-
space indents is a very common standard, and that it is recommended by 
Guido and required for the standard library, but it is not the only 
standard, not even for Python code.

I managed to avoid all the tedious arguments about which braces style 
(for C programmers) or BEGIN/END positioning (for Pascal programmers) was 
"THE" standard. I would have hoped that in the 21st century we'd got past 
that nonsense. By all means argue that interoperability with others is 
generally a good thing, and 4-space indents is sufficiently common that 
it maximizes your ability to interoperate. You won't get any arguments 
from me. (That's why I use 4-space indents, even though they are an 
Abomination Unto Nuggan.)

But let's not pretend that Windows is "THE" standard operating system, 
vanilla "THE" standard ice cream flavour, and 4-spaces "THE" standard for 
indents. If interoperability is not important to you, go right ahead and 
use any standard you like, or even pick something non-standard like 17-
space indents. There's no Indent Police who will arrest you for failing 
to live up to the standard.



-- 
Steven



More information about the Python-list mailing list