Tabs or Spaces?

Mentioned yesterday that I’ve been enjoying being part of a team programming project for the first time. One of the interesting things that comes up in a cooperative environment are all the conversations about preferred coding style — it’s not just you anymore, Buck-o. We’re all going to have to find a way to make our code flow together nicely. Conditional style, case preferences, and something I never knew was a long-standing religious debate before: tabs vs. spaces. All have been part of the conversation over the past six weeks (and all resolved amicably, FWIW).

Now the WordPress Hackers mailing list is having a protracted debate over the tabs. vs. spaces issue (apparently the first time it’s come up in three years). Jeremy Zawinski has a famous piece in favor of spaces. Lots of good arguments go the other way. I know where I stand. You?

Tabs or Spaces?

View Results

18 Replies to “Tabs or Spaces?”

  1. The usual reasons, but the big one for me is that I don’t want to necessarily have to configure my text editor to make source pretty to look at. If I’m on a strange machine and just want to bring up some code in Notepad or TextEdit (in lieu of a real editor) I don’t want it to look all buggered up.

    On top of that, I find that tabbers rarely use tabs 100% of the time, so you get a bizarre mix of tabs and spaces (tab then space, space then tab, even just occasionally as a mistake, etc), which can be a total mess… Spaces are constant and predictable.

    Most of my arguments against tabs can be fixed by having people adhere to coding standards. Unfortunately, you can only do that if they have financial incentive to do so…. At work, we have very clear coding standards, and scripts to monitor the source tree to ensure they are being obeyed…

  2. I’m more-or-less with Sean (although not so militant) – I love the idea of tabs, but in practice they just never seem to work out.

  3. Interesting, we’re building up toward an even split here.

    I’m on the tab side. Probably because that’s what I learned and all I’ve ever done, but it does feel the most logical to me, since tabs are abstract — the width of a tab is up to the displaying editor. If I like narrow indentations and you like wide ones, we can both have our way at the same time by configuring our editors differently. And I like that tabs save bytes. And I like that I can indent entire blocks of code cleanly and quickly with tabs (maybe this is possible in vi with spaces as well as with tabs, though I don’t see how)

    I do agree that it’s a mess when they’re mixed, but disagree with Sean that tab people tend to use both tabs AND spaces. It would never occur to me to indent code with a space, so I don’t do that. Though others might.

    The WordPress codebase is all tab indented, and according to the mailing list traffic, the topic had never come up until now – everything’s been humming along merrily.

    My space-centric comrade reports that after using tabs for a month on this project he’s grown to like them.

  4. From the WordPress Codex on coding style:

    Indent! Your indentation should always reflect logical structure. Use real tabs and not spaces, as this allows the most flexibility across clients.

  5. And I like that I can indent entire blocks of code cleanly and quickly with tabs (maybe this is possible in vi with spaces as well as with tabs, though I don’t see how)

    Actually, Zawinski’s article linked above contains notes on how to configure vi/vim to do this, but also makes the larger point that the safest bet is to go ahead and use tabs while coding but configure your editor to convert tabs to an equivalent number of spaces while saving to disk (in BBEdit this is the entab/detab command). Which makes a certain amount of sense.

  6. I like tabs.

    (I also like pie, but that’s another story).

    However, as Sean and Dan point out, tabs all-too-often turn into a strange mix of tabs and 4/8-spaces.

    So I’ll use tabs for code that I make, but I rarely just the tabs of others.

  7. Diffing source code with tabs always ends up looking bad. Huge indents and other problems. Every place I’ve ever worked has eventually settled on spaces and all the good editors and IDEs know how to insert tabs as spaces and read spaces as tabs.

  8. Ooh, that would be a fun one. But unlike tabs v spaces, editor choice isn’t binary, so I’d have to list a couple dozen options. Hmm… actually, this poll plugin does have an option to let users add new choices, which I’ve never tried, and which seems would be disastrous for accuracy of the results, but could be fun.

  9. Spaces, for me. Seems like it can be hard to get everyone to be consistent about tab usage.

    However, vim does make it easy to deal with either tabs or spaces:

    First of all,
    :set tabstop=N

    Then, to convert new tabs to spaces as you type
    :set expandtab (or :set noexpandtab if you like tabs)

    And to fix a tab formatted file by converting all tabs to spaces
    :retab (or :retab N, where N is the new tabstop value)

  10. Tabs for me (at least I’m consistent with them). People who use spaces people aren’t always consistent either. I’ve seen indents ranging anywhere from 2-4 spaces (sometimes within the same piece of code). At least with tabs, I can do a search and replace to convert it to whatever space-width that’s needed. And if people just stick with tab sizes of 8 spaces, you’ll definitely notice any mix of tabs/spaces. To all the spaces proponents, have you even tried using tabs?

  11. Old thread but way relavent topic. I’ve been a fan of tab characters for 20 years but I’ve decided to abandon them completely and to even take Sean’s militant stance! (but not because of Sean’s arguments mind you.. ;)

    The only reason *for* tabs is it makes for smaller source files. Now days hoever *zip makes short work of all repeating character sequences so the only reason for tabs has gone away.

    From the WordPress Codex on coding style: Indent! Your indentation should always reflect logical structure. Use real tabs and not spaces, as this allows the most flexibility across clients.

    Yes always indent to reflect logical structure but never use a tab character to do it. The problem is there is no longer a standard for the definition of a tab – it used to be “stop at the next modulo8 column” – but then people were given the chance to “adjust” this WITHOUT defining their abstraction within the given document… and now we have a complete mess. Spacs are now the only well defined whitespace (that doesn’t break a line).

    The action of the tab key and the presence of a tab character have now become totally orthoganal concepts. What source editors do when you press tab should no longer ever include inserting a 0x9 into a document…

Leave a Reply

Your email address will not be published. Required fields are marked *