indentation

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Mon Oct 20 09:29:16 EDT 2008


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."


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.


Here's Jamie Zawinski:
http://www.jwz.org/doc/tabs-vs-spaces.html

"On defaultly-configured Unix systems, and on ancient dumb terminals and 
teletypes, the tradition has been for the TAB character to mean ``move to 
the right until the current column is a multiple of 8.'' (As it happens, 
this is how Netscape interprets TAB inside <PRE> as well.) This is also 
the default in the two most popular Unix editors, Emacs and vi."


This page is a little old (2002), but it states that the standards for 
OpenBSD and Linux (presumably the kernels) are 8 space indents:

http://xarg.net/writing/tabs

Here's a style guide that recommends 2, 3 or 4 space indents:

http://www.cs.bris.ac.uk/Teaching/Resources/COMS12100/style/


And of course, whenever there's a difference of opinion, we can turn to 
the ultimate source of all knowledge: Googlefight!  *wink*

http://www.googlefight.com/index.php?lang=en_GB&word1=tab+8
+spaces&word2=tab+4+spaces

Nearly 50 million hits for "tab 8 spaces" versus a piddly 762 thousand 
hits for "tab 4 spaces".



-- 
Steven



More information about the Python-list mailing list