[Tutor] Pep 8, about indentation

Steven D'Aprano steve at pearwood.info
Thu Aug 6 05:40:08 CEST 2015


On Thu, Aug 06, 2015 at 02:24:49AM +0100, Alan Gauld wrote:
> On 06/08/15 00:31, D Wyatt wrote:
> >I clearly remember that the standard for Python was to use 2 spaces
> 
> Nope, unless it was a local convention in your place of work.
> 
> But the standard for indentation has always(*) been 3 or 4 and fro PEP 8 
> its 4. And thats pretty standard in any language because its the size of 
> indent that gives best clarity to the code. (Based on tests of students 
> reading code samples.)

Um, the oldest standard for TABs is *eight* spaces, not 3 or 4, and 
using eight-space indents is still very common. Vim, apparently, 
defaults to 8 space indents when you hit the tab key. Gofmt (used by the 
Go language) defaults to 8 spaces; even Python does in places:

expandtabs(...)
    S.expandtabs([tabsize]) -> str

    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 Linux kernel developers use 8 space indents, and consider that 
important enough that it is the very first item in their style guide:

https://www.kernel.org/doc/Documentation/CodingStyle

For interest, here's a survey done by Perl programmers in 2002:

http://www.perlmonks.org/?node_id=158886


-- 
Steve


More information about the Tutor mailing list