On Indentation
I don't understand why so many otherwise intelligent programmers insist on using spaces to indent lines of code. The whole purpose of a tab is to advance the cursor to a specific position. These positions are customizable in every capable editor out there. Why force your formatting on everyone who has to read or edit your code? It's not like you sit there and hit the spacebar 2, 3, 4, or 8 times; you hit tab and tell your editor to translate it to spaces. In fact, you go to great lengths to have your editor pretend a group of spaces at the beginning of a line is one unit -- a tab, if you will. What's the point? A tab is the semantically correct equivalent.
This is especially aggravating in an environment where more than one person, each with his own indentation preference, is editing code. Even if you mandate that each developer must use spaces for indentation, and further, that they must use a specific number of them, the developer is still left with the problem of changing his editor preferences each time he wants to work on that project. This is further compounded when you have developers working on multiple projects, each with different "settings" due to managerial differences.
Tabs are the One True Way. Anyone who tells you otherwise is likely a creature of archaic habit, or downright misinformed.
Comments
-
colin
June 21, 2006 -
I concur. That's why we set coding starts at the start of project. And if old code doesn't match, we use Eclipses awesome reformat with a click of a button to fix all identation.
-
imdeano
September 01, 2006 -
I disagree. I think that spaces are the one true way since they don't change. Tabs move around depending on default settings. Also, most of the python library and DVR use spaces.
http://keithdevens.com/weblog/archive/2006/Jan/10/GvR.status
-
Dan Watson
September 02, 2006 -
Spaces move around as well. They just move based on policy, not preference. How would you like working on a project that mandated 8-space indents? 7? 16? 3?
It strikes me as especially silly that people would use spaces for indentation in python, where the level of indentation matters. A one to one relationship between tabs and levels seems incredibly sane for such a language.
-
Jason
September 10, 2006 -
I've made this argument for quite some number of years but most 'spaces' advocates disregard it. In general, 'spaces' people tend cite examples like this:
function(int a, string b, ...This is tough to do with tabs, and if you have any stray linebreaks in your code to make it span a few lines you will probably force the reader of your code to use a tabstop close to what you originally intended anyway. In python you don't often have the opportunity to do this. I used to use strictly tabs when coding in python, but since the language itself and many 3rd party libraries all use spaces, I've changed my habits.
-
Dan Watson
September 10, 2006 -
Personally, I can't stand code that puts every function argument on it's own line. But if you must do that, I'd say an exception could be made for using spaces for the sake of alignment, but not indentation. A more ideal solution would be editors with better language support. Being able to set preferences for how you want to see function arguments, how you want multi-line array initializers formatted, etc. Eclipse comes close, but there's still room for improvement.
The fact that, like you said, you don't see these kinds of things in python very often only further supports my case for using tabs.
-
Tyson Tate
October 02, 2006 -
I completely agree with you, Dan.
In addition to your reasons, one of the reasons I like tabs is that I can change the indentation level based on what kind of code I'm editing. If I'm neck-deep in some crazy many-nested loop and conditional algorithm, I can make the tabs nice and wide to improve legibility. If I'm working with a dense chunk of code that needs to be squeezed on to one line, I can squeeze the tabs down to one or two spaces wide.
With forced spaces, I don't have that option.
I really can't see a single downside to using tabs.
-
Jason Toffaletti
October 04, 2006 -
Hey Dan, long time. Good to see you're doing well.
I agree that tabs make the most sense in theory, but in practice they cause way too many headaches (especially with python) to justify.
http://www.jwz.org/doc/tabs-vs-spaces.html http://www.python.org/dev/peps/pep-0008/
These were both written by very smart people with more combined programming experience than you or I will likely ever have and they agree, spaces is the way.
I use spaces now because I got tired of having to reformat code that was written with spaces when pasting it into my code that used tabs. The reverse is much easier because the editor does it automatically. Reformatting code that uses a different number of spaces to match my spacing is rarely needed and much easier.
-
Dan Watson
October 04, 2006 -
Hey Jason, it's good to hear from you!
I've read both the pieces you linked to. jwz seems to say, "the real problem is some people like to see 4 columns, some people like to see 2" and then goes on to suggest that everyone pick one and stick to it. Why not have your cake, eat it, and then let someone else have a bite?
As for Guido, I realize the informal python coding conventions call for spaces, but if you go back far enough, he was a tab guy as well. I agree that it's a pain in the ass dealing with two different pieces of code, one formatted with tabs and the other with spaces. But the situation could just as easily be solved by everyone using tabs as it could by everyone using spaces. It may not be the most popular opinion, but I think it's the right one :-)

June 02, 2006
OH SNAP!!!!!11