473,780 Members | 2,258 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why Python style guide (PEP-8) says 4 space indents instead of 8 space??? 8 space indents ever ok??

Linux kernel style guide, Guido's C style guide and (I believe) old
K&R style recommends 8 SPACES for indent.

I finally got convinced of wisdom of 8 space indentation.

Guido also likes 8 space indentation FOR C CODE.

Why style guide (PEP-8) for Python says 4 space indents???

Is breaking rule to use 8 space indents everywhere
a REALLY bad idea??

I REALLY WANT TO DO MY OPEN SOURCE PYTHON PROJECT
WITH 8 SPACE IDENTS!!!!

Chris
Jul 18 '05 #1
21 4027
Christian Seberino wrote:
Linux kernel style guide, Guido's C style guide and (I believe) old
K&R style recommends 8 SPACES for indent.

I finally got convinced of wisdom of 8 space indentation.

Guido also likes 8 space indentation FOR C CODE.

Why style guide (PEP-8) for Python says 4 space indents???

Is breaking rule to use 8 space indents everywhere
a REALLY bad idea??

I REALLY WANT TO DO MY OPEN SOURCE PYTHON PROJECT
WITH 8 SPACE IDENTS!!!!

Chris


I don't have an official answer, but here are my guesses:

a)

In C, new lines are generally like any other white space (except within
strings, C++ // comments), so you can easily put new lines in the middle
of an expression.

In Python, newlines are significant, except within lists, tuples, etc.
and a few other cases, so you generally have to escape them with \
within statements. If you use 8-space indents in Python, you very
quickly end up having to escape a lot of new lines, which is annoying.

b)

Unless you have an editor which converts tabs to a fixed number of
spaces, typing 8 spaces is a pain. Even editors which do convert tabs
to spaces may not provide an easy way to un-indent by the same number of
spaces

--------

Of course, both these reasons would imply that 2 spaces was better than
4. Using 4 spaces was probably chosen as a compromise between points a)
and b) and making sure that the indentation level was clearly visible.

David

Jul 18 '05 #2
Christian Seberino wrote:
I REALLY WANT TO DO MY OPEN SOURCE PYTHON PROJECT
WITH 8 SPACE IDENTS!!!!


You don't really think a style guide is going to stop you from doing
that, do you?

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ Golf is a good walk spoiled.
\__/ Mark Twain
Jul 18 '05 #3

"David C. Fox" <da*******@post .harvard.edu> wrote in message
news:FYDlb.2596 $e01.5531@attbi _s02...
In Python, newlines are significant, except within lists, tuples, etc.
and a few other cases, so you generally have to escape them with \
within statements. If you use 8-space indents in Python, you very
quickly end up having to escape a lot of new lines, which is annoying.

As a side note, Python considers a tab to be == 8 spaces. So you can mix
spaces and tabs in a single file as long as you use an 8-space convention.
Now, if your editor displays \t as something other than 8 spaces (I think 8
is default in almost every editor, though), the indentation can LOOK wrong,
even though Python has no trouble with it!

Given that 4 spaces is overwhelmingly dominant in Python code, shouldn't
that behavior be changed, so that '\t'==' '*4?

Or perhaps python should have a heuristic, where the first first-level
indent in the file which is indented entirely by spaces establishes the
number of spaces that a tab character should be equivalent to.

(Or maybe it shouldn't, since mixing spaces and tabs is bound to cause
trouble eventually, and better to find out sooner than later...)
--
Francis Avila

Jul 18 '05 #4
Francis Avila wrote:

Given that 4 spaces is overwhelmingly dominant in Python code, shouldn't
that behavior be changed, so that '\t'==' '*4?

Or perhaps python should have a heuristic, where the first first-level
indent in the file which is indented entirely by spaces establishes the
number of spaces that a tab character should be equivalent to.


Anyone who believes there is or will be anything new in this discussion
hasn't been reading comp.lang.pytho n or the mailing list nearly long enough.

Check the archives if you are having trouble falling asleep tonight,
and keep in mind the utter futility of writing anything more on this
subject (unless you just like to see yourself in print). :-)

-Peter
Jul 18 '05 #5
se******@spawar .navy.mil (Christian Seberino) wrote in message news:<bf******* *************** ****@posting.go ogle.com>...
Why style guide (PEP-8) for Python says 4 space indents???


Never heard of that. I guess I need to read less about programming
and more about style. I use 2 space indents. Easy to type, easy to
change, and I'm never tempted to use tabs instead...

--Stan Graves
st**@SoundInMot ionDJ.com
http://www.SoundInMotionDJ.com
Jul 18 '05 #6
so************* @yahoo.com (Stan Graves) writes:
Never heard of that. I guess I need to read less about programming
and more about style. I use 2 space indents. Easy to type, easy to
change, and I'm never tempted to use tabs instead...


In non-Python-aware editors (like Usenet messages), I prefer 2-space
indentation as well. While programming larger projects, I use a
Python-aware editor, and that editor makes indentation automatically
(to four spaces), so it is just as easy to type.

Regards,
Martin

Jul 18 '05 #7
Erik Max Francis <ma*@alcyone.co m> wrote in message news:<3F******* ********@alcyon e.com>...
Christian Seberino wrote:
I REALLY WANT TO DO MY OPEN SOURCE PYTHON PROJECT
WITH 8 SPACE IDENTS!!!!


You don't really think a style guide is going to stop you from doing
that, do you?


Keep looking over your shoulder! Only if you expect the (style guide)
Spanish Inquisition, will they never show up. That's your only
protection if you're an eight spaces heretic. ;-)

Paul

P.S. Seriously, most people respect the indentation of the project
"lead" on open source projects - for example, Webware employs hard
tabs throughout its source code, and yet very few people go in and
mangle the code with two space indents and other such misdemeanours.
Some people claim some kind of inherent superiority with "whitespace
insensitive" languages, but I imagine that they are members of that
irritating club who go into C++ files and trash the indentation,
claiming that "it looks OK in Visual Studio". I suppose that this is
another area where Python almost inadvertently encourages more
considerate programming practices.
Jul 18 '05 #8

"Francis Avila" <fr***********@ yahoo.com> wrote in message
news:vp******** ****@corp.super news.com...

"David C. Fox" <da*******@post .harvard.edu> wrote in message
news:FYDlb.2596 $e01.5531@attbi _s02...
In Python, newlines are significant, except within lists, tuples, etc.
and a few other cases, so you generally have to escape them with \
within statements. If you use 8-space indents in Python, you very
quickly end up having to escape a lot of new lines, which is annoying.

As a side note, Python considers a tab to be == 8 spaces. So you can mix
spaces and tabs in a single file as long as you use an 8-space convention.
Now, if your editor displays \t as something other than 8 spaces (I think

8 is default in almost every editor, though), the indentation can LOOK wrong, even though Python has no trouble with it!
I considered not dropping into this conversation, since Peter Hanson's
reply is absolutely correct - the subject is dead and won't be revisited.
However, there are two errors in the previous paragraph that I think
need to be addressed.

First, Python, along with most xNIX sofware, considers a tab to
be an instruction to move to the next column that is a multiple of 8
(or 8 + 1 if you're starting at 0.)

It's also regarded as ***VERY*** bad practice to mix spaces
and tabs for indentation, and you are guaranteed to get bad results
if you move between editors that have the default number of spaces
to generate for tabs set to something different. In fact, the ability
to use tabs at all for indentation may very well vanish in Python
3.0 (although not sooner.)
Given that 4 spaces is overwhelmingly dominant in Python code, shouldn't
that behavior be changed, so that '\t'==' '*4?

Or perhaps python should have a heuristic, where the first first-level
indent in the file which is indented entirely by spaces establishes the
number of spaces that a tab character should be equivalent to.
Historically, Python has had the ability to identify the footprint that
a number of popular editors leave in the file. This has never been
documented, and since I don't use emacs, I don't know if it's still
in the current version of Python. It may not be, since it's only useful
if you mix tabs and spaces, and that's been identified as bad practice.
It's also not completely compatible with the character set comment
in 2.3
(Or maybe it shouldn't, since mixing spaces and tabs is bound to cause
trouble eventually, and better to find out sooner than later...)
Most editors can be set to generate spaces when you use the
tab key. It's the recommended practice with Python.

John Roth

--
Francis Avila

Jul 18 '05 #9
Peter Hansen <pe***@engcorp. com> wrote in message news:<3F******* ********@engcor p.com>...
Anyone who believes there is or will be anything new in this discussion
hasn't been reading comp.lang.pytho n or the mailing list nearly long enough.


Yeah, the eternal, never-ending war between the tabibans and the tabifans.

Hung Jung
Jul 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1117
by: Maxim Khesin | last post by:
Is there anything like a style guide geared towards larger projects? I am particularly interested in module handling (size, complexity, intermodule dependencies). thanks max
22
2220
by: beliavsky | last post by:
Is there a more recent set of Python style guidelines than PEP 8, "Style Guide for Python Code", by van Rossum and Warsaw, at http://www.python.org/peps/pep-0008.html , which is dated July 5, 2001?
9
1501
by: Leif K-Brooks | last post by:
I try to make my code comply to the Python style guide (http://www.python.org/peps/pep-0008.html). Last time I read it, I swear that it said to use CamelCase for often-used functions and lower_case_with_underscores for rarely-used utility functions. Now it says to use low_case_with_underscores for everything, but it claims to be last updated in 2001. Am I crazy?
4
1346
by: Fredrik Lundh | last post by:
(reposted from doc-sig, which seems to be mostly dead these days). over at the pytut wiki, "carndt" asked: Are there any guidelines about conventions concerning punctuation, text styles and language style (e.g. how to address the reader)? any suggestions from this list ?
2
1964
by: Giggle Girl | last post by:
Hello there! I am a User Interface Designer at a company that only makes web apps. I am fluent in HTML, Javascript and Graphics programs. Now we are making a compiled app with VS05 in C#, and I have to make the forms by primarily drag'n'dropping controls using the WYSWIG editor built into VS05. I have these questions: QUESTION 1. Is there a horizontal rule, or vertical pipe, to visually separate the layout?
8
1423
by: Darren Dale | last post by:
I was just searching for some guidance on how to name packages and modules, and discovered some inconsistencies on the www.python.org. http://www.python.org/doc/essays/styleguide.html says "Module names can be either MixedCase or lowercase." That page also refers to PEP 8 at http://www.python.org/dev/peps/pep-0008/, which says "Modules should have short, all-lowercase names. ... Python packages should also have short, all-lowercase names...
0
9636
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10306
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10139
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6727
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5504
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.