1

Edit: This question has already been asked and answered, and I apparently am not good at using the search wizard. See Why does Python pep-8 strongly recommend spaces over tabs for indentation? and the link in the comments. Thanks for replying to those who did so.

I want to start a new project, and I want this to be my first Python project. I was looking through the style guide, http://www.python.org/dev/peps/pep-0008/, which "strongly recommends" using a 4-spaces indentation style for new projects. But I just hate this idea! In my opinion, tabs are better for this purpose.

What annoyances could crop up one day if another developer wanted to work on my tab-delimited files?

Community
  • 1
  • 1
masonk
  • 9,176
  • 2
  • 47
  • 58
  • 3
    See http://stackoverflow.com/questions/119562/tabs-versus-spaces-in-python-programming for a very similar discussion about tabs vs. spaces. – Justin Ardini Mar 29 '10 at 02:02
  • Conventions are there for a reason. – Humphrey Bogart Mar 29 '10 at 02:10
  • Is this a solo project, or with other developers? There are a lot less potential tab/space problems if this is just something you're doing on your own. – Tyler Mar 29 '10 at 02:14
  • Why don't you like the idea? There is a least one *very* popular email client that eats tabs when you email code snippets, which is why I stopped using tabs years ago. It's just not worth the bother. Most editors can be configured to insert/delete 4 spaces as if they were tabs and makes life a lot simpler. – John La Rooy Mar 29 '10 at 07:07
  • re: gnibbler Basically, I think it comes down to an intent issue. Asking spaces to serve as both the means of separating tokens and as the way to designate program structure is not separating concerns well. From this root evil, other problems arise, such as the display issue: Tabs can be displayed at any width the user prefers. Finally there is just more information in a tabbed document: demonstrable by the fact that tabbed documents can be converted into spaces perfectly, but spaced documents can be converted to tabbed only heuristically. – masonk Mar 29 '10 at 12:30

2 Answers2

1

Most Python programmers will have their editors configured to automatically use four spaces for all .py files… Which could, at least initially, cause some minor headaches if they try to edit your source.

But apart from that (given that PEP 666 was rejected), it shouldn't cause any major trouble.

Of course, if you get serious about Python, it would be a good idea to follow PEP 8, as most Python code conforms to it… But, given that this is your first Python project, you've got bigger things to worry about than tabs VS spaces.

David Wolever
  • 148,955
  • 89
  • 346
  • 502
1

If all the world used tab-indented Python source, then everyone would be happy. If all the world used 4-space indented Python source, then everyone would be happy.

Unhappiness arises when one tries to comingle tab-indented code with 4-space indented code.

The majority of Python code seems to be of the 4-space variety. If you ever wish to rip out some of this code and use it in your project, you will be saved from the minor annoyance of having to run it through a space-to-tab converter (like unexpand) if you stick with the PEP recommendation and use 4-spaces.

You'll also cause less of a hassle for other developers (who follow the 4-space convention) who may wish to contribute to your project.

PS. Finding a good text editor is especially important when writing code in Python. It should allow you to press [TAB] and insert 4 spaces instead of 1 tab. It should also allow you to be able to shift blocks of code by 1 level of indention to the left or right easily. Once you find the right editor (e.g. emacs or vim), working with the 4-space convention is a breeze.

unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677