Why tabs are clearly superior

If you follow me on twitter or have heard one of my talks you’ll probably know I despise spaces for indentation with a passion. However, I’ve never gone into the details of my opinion on stage, and twitter isn’t really the right medium for advocacy. I always wanted to write a blog post about my take on this old debate, so here it is.

Tabs take up less space

Yes, this might be an insignificant difference after gzipping and a nonexistent one after minification. But it means you need these processes to keep your code size reasonable. You depend on them, for no reason. Comments for example are useful, and it’s worth having them even if you knew you couldn’t minify or gzip your code. Tabs could do the same thing as spaces, so you’re just bloating your code for no reason.

Tabs can be personalized

The width of a tab character can be adjusted per editor. This is not a disadvantage of tabs as commonly evangelized, but a major advantage. People can view your code in the way they feel comfortable with, not in the way *you* prefer. Tabs decouple the code’s presentation from its logic, just like CSS decouples presentation from HTML. They give more power to the reader rather than letting the author control everything. Basically, using spaces is like saying “I don’t give a rat’s ass about how you feel more comfortable reading code. I will force you to use my preferences because it’s my code”.

Tabs are better for collaboration

Personalization is incredibly valuable when a team is collaborating, as different coders can have different opinions. Some coders prefer their indents to be 2 spaces wide, some coders prefer them to be 4 spaces wide. Rather than manually or automatically converting the code post-pull, and then back pre-commit, it would be adjusted automatically, depending on the editor’s tab-width setting, so every coder could start editing right away, with their favorite type of indent.

You don’t depend on certain tools

When using spaces, you depend on your editor to hide the fact that an indent is actually N characters instead of one. You depend on your editor to insert N spaces every time you press the Tab key and to delete N characters every time you press backspace or delete near an indent. When you have to use something that’s not your editor (for example when writing a snippet of code on a webapp that embeds something like codemirror) you will have to face the ugliness of your decision. Especially with codemirror, everyone else will have to face the ugliness of spaces too, as it converts tabs to spaces :(

Tabs are easy to select

Assume for some reason you want to select all indents and double them or convert them to spaces. This is very easy with tabs, because that’s their sole meaning. Tabs were invented for this sort of thing. Spaces on the other hand, have many meanings, so you can’t just find & replace space characters. And how do we usually call the practice of using things for a different purpose than they were made for? Yup, that’s right, using spaces for indentation is a hack.

Code indented with tabs is easier to copy & paste

As pointed out by Norbert Süle in the comments, when you copy and paste code that’s indented with spaces, you have to manually adjust the indentation afterwards, unless the other person also happens to prefer the same width indents as you. With tabs, there is no such issue, as it’s always tabs so it will fit in with your (tabbed) code seamlessly. The world would be a better place if everyone used tabs.

But what about the web? Tabs are super wide there!

This used to be a big problem, and even the enlightened coders that prefer tabs usually convert them to spaces before posting code online. However, CSS3 solves this problem, with the tab-size property. It’s supported by Opera, Firefox and very soon by WebKit too. It also degrades gracefully: The code is less pretty, but still perfectly readable.

Are spaces always evil?

Spaces are the best choice for aligning, rather than indenting. For example, in the following code snippet:

var x = 10,
    y = 0;

you need 4 spaces to make the variables line up. If you used tabs, they would only line up when the tab width is 4 and the formatting would look messed up in every other case. However, if this code snippet was also indented, the indents could (and should) still be tabs.

Another example is aligning CSS3 properties with different vendor prefixes. The indent should be done with tabs, but the aligning with spaces, like so:

div {
	-webkit-transition: 1s;
	   -moz-transition: 1s;
	    -ms-transition: 1s;
	     -o-transition: 1s;
	        transition: 1s;
}

It’s just a pointless detail, are you seriously that obsessed?

Um, ok I am exaggerating a bit when I say how spaces suck. I do think they suck, although I admit the world has much bigger problems than coders who use spaces for indentation.

For example, coders that don’t name their variables properly. Or the ones that prefer Emacs over Vim ;)

Further reading

 
Thanks to Oli  for his proofreading!
  • Tab Atkins

    Final reason: because I’ve never met anyone named “Space”.

  • Anonymous

    Yup. Totally agree. Thanks for putting the reasons in writing. =)

  • Sander Aarts

    em vs px

  • Anonymous

    YES! Another strong win for us Tab people! Thank you :) 
    another disadvantage of space-indented code is what I call the “asshole” principle. If I were using spaces to indent, I could be an asshole and indent with 1 space per level! Any normal person that opens the file would have to make sure his/her IDE or text editor is configured correctly to convert the spaces,  and convert back (like you said with committing). It’s just a mess.

  • http://glyph.twistedmatrix.com/ Glyph

    Tabs don’t decouple a code’s logic from its presentation.  A structure-aware editor is what does that decoupling.  We need more tools that can understand the shape of our code and free us from these kinds of pointless debate.  Graphic designers don’t put up with manually serializing their PNGs and JPEGs, why do all of us who write code put up with tools that make us constantly decide about pointless ephemera like this?

    But, until everyone uses such tools, following local convention is far more important than any particular rule.  For new projects, you may feel free to use tabs; unless you’re using Python, where 4 spaces is always the rule :).

    • antred

      Python doesn’t require 4 spaces per indentation level, it’s merely recommended (sadly).

  • http://oli.jp/ Oli Studholme

    Spaces AND tabs!? What new devilry is this!????
    http://www.emacswiki.org/emacs/TabsSpacesBoth

    Also, everyone knows Emacs is teh best. What do you mean, a world PROBLEM!?!?
    infidel!
    :|

  • http://beeminder.com Daniel Reeves

    Heresy! I shall attempt a rebuttal:

    1. Less space. Commenting on this point would waste too much space!

    2. Can be personalized. My code is a precious, precious work of art and you should not be changing the indentation! That would mess everything all up! (Slightly serious. I’m also religious about 80 characters per line, for reasons of space efficiency: if some lines are much longer than average then most of your editor window will be empty space to accommodate them.)

    3. Better for collaboration. See above.

    4. Certain tools. You do depend on them! More so! Because everything will be fubar unless the editor is set to interpret tabs the way you intended. You’re saying you depend on your editor to insert N spaces when you hit tab. I guess so, but aren’t you relying on editor cleverness to jump you to the right indent level anyway? I use 2 spaces per indent so not much difference in my mind.

    5. Easy to select. You often want to slide a block of code right or left, and I suppose that with tabs you have another option for doing so (not a very good option, I don’t think). You never want to do a global search and replace on tabs, except of course to convert them to spaces!

    6. Spaces aren’t evil, unless mixed with tabs. Like you say, you want spaces sometimes for aligning things. But you suggest that in that case you can just *mix spaces and tabs*. That hurls us into a dark pit of befuddled despair!

    I too may be exaggerating. I actually feel more strongly about indentation being only 2 spaces wide than I do about spaces vs tabs. So I’d rather you give me code with tabs than code with 4-space indentation. Which may mean I just defeated my whole case.

    • http://leaverou.me Lea Verou

      Which may mean I just defeated my whole case.

      Yes you did, haha :D

    • http://twitter.com/sbrandwoo Stephen Brandwood

      The 80 characters is a very good point though. If we strive for short line lengths for portability, hope do we cope with someone with a large tab-width setting?

      True portability can only be achieved if you can control how the output will be displayed, and this can only happen with spaces.

      P.S: 2 spaces? you madman!

  • Anonymous

    exactly!

  • http://twitter.com/nek Thibaut Allender

    Back in the 90s there was no gzipping on the web and trust me, table layout code was usually huge AND needed to be indented correctly. No need to say you wanted to use Tabs instead of spaces with those tiny modems… Yep, size mattered and still does. I’ve always used Tabs and will always use them.

    • http://profiles.google.com/shannon.thrasher Shannon Thrasher

      im a tabs person myself, but most professionals use minifiers in their build to (among other things) *preserve space* I think this is the point that tries to totally invalidate the size argument.

  • http://profiles.google.com/bhofmann.hotmail.co.uk Bernhard Hofmann

    I still maintain that tabs and coding style are a presentational issue. Our tools are failing to abstract us from the underlying implementation of the code.  Whether I use tabs or spaces, Allman or K&R style should be irrelevant; the code is code, not the layout of the characters in the file. I wrote a note about this a few years ago:

    “I would like it to know that a source code file should be stored in a certain format. This would allow me to use tabs and Allman style, whilst other colleagues could use spaces for indentation, and K&R style. I suspect it would then either be a case of the SCM storing the code in the most efficient format and converting to user-style when the file is retrieved from the repository. This would still allow me to use my preferred text-based diff tool to compare code written by myself and others, without having to worry about extra blank lines and braces in the wrong place, tabs and space indentation. The focus would not be on code-representation, but the code itself.”Source:  http://bernhardhofmann.blogspot.com/2009/06/source-control-and-diff-software.html

    • http://leaverou.me Lea Verou

      Completely agree!

    • Anonymous


      I still maintain that tabs and coding style are a presentational issue. ”
      Couldn’t agreee more. That’s all that it is. 
      I just 

    • Stephen Wotton

      I completely agree Bernhard, this would be the most comprehensive solution.

  • Panagiotis Astithas

    I used to share your preference years ago, as well as most of your arguments. In my case, the first one that got shot down was the tools. At first it seems that tabs leave you free to set your editor to your personal preference, but the reality is that not all tools are as configurable. And of those that are, you are not always in a position to alter them. Think of hg, git, cat, diff, etc. Not what you’d normally think of as “your tools”, but it’s what all of us use along with our editors. Not much configuration there for tabs. And then think about other tools that embed these tools, like GUI apps and web apps. Like Google Code, or GitHub. Can you get those to use 4 characters per tab?

    Everybody agrees that it’s more important to not mix both tabs and spaces, than to pick a horse in this race. But reaching an agreement about indentation size (or maximum line size, etc.) is predominantly a collaboration concession. It just happens to tie in with the tool limitations. If you prefer 8 char tabs and I prefer 2 char spaces, when one of us reviews the other’s diff on Google Code or Bugzilla, won’t he necessarily have to concede to read code in an unfamiliar format?

    The collaboration card is held by spaces. If you need to work with others, it’s in your best interest to remove all obstacles to collaboration and in most cases, this means settle on a common denominator. Spaces are solid. They cannot be misinterpreted. They don’t change from one workspace to another.

    If they were people, you’d be hanging out with them and buying them beer!

    • http://leaverou.me Lea Verou

      Sigh. 

      Frankly, I don’t think you read *anything* past the titles in this post. I have addressed pretty much all your points in it.

      • Panagiotis Astithas

        To be fair, I did read all of it before commenting. Twice actually. Three times by now, after reading your comment. I still don’t see your counterpoints, but maybe I’m just dumb. That’s OK. At least I should get some credit for trying! :-)

        • http://leaverou.me Lea Verou

          Ok, lemme try to help:
          a) Your points about web apps are answered with tab-size. It could be in your user stylesheet too ;)b) “Everybody agrees we shouldn’t mix tabs and spaces” -> Um, no. Many people, including myself think the best way to go is using tabs for indenting and spaces for alignment. Everybody agrees we shouldn’t be inconsistent, as in, using spaces for indentation in one code block and tabs in another.
          c) Your point on collaboration doesn’t even attempt to refute my arguments about how tabs are better for collab. It’s as if you never read that part beyond the heading.
          d) “If you prefer 8 char tabs and I prefer 2 char spaces” Then we just use tabs and I set a width of 8 and you set a width of 2. Problem solved.

          Also, I’ve never, ever had issues with git & tabs, so not sure what you’re talking about there.

        • Statements and Blocks

          The interesting thing is that tabs were designed for alignment. Originally, they were tab stops, and they were at specific “distances” from the margin. 

          So the real problem here is that your editors are all broken wrt tabs, since tabs actually have nothing to do with spaces originally. (Hint, look at any word or desktop publishing program, tabs are not set by # of chars)

    • billy bob

      “Spaces are solid. They cannot be misinterpreted. They don’t change from one workspace to another.”
      This is wrong!  TextEdit (on a Mac) vs Notepad on a PC vs DW code view vs BBEdit. Character spacing is different in nearly every editor available.

      You’ve never tried to convert an MS Word Doc to another Editor before have you ?

      • http://twitter.com/geekbrit Peter Maloy

        Are you seriously suggesting that anyone would use MS Word as a programmer’s text editor?

      • Br. Bill

        We are clearly not talking about situations in which a proportional font is being used. That is entirely different from most programming editors.

  • Hanzi Fey

    spaces just feel more right for indentation

  • http://twitter.com/IllusionMH 109th

    I’m using spaces! Yes, I said that.
    Did you try to code in textareas where Tab key means switching to next element? I hate this kind of pages, but there is no another option((
    In this case I prefer use 2 spaces, not Shift + Tab.

    In my own projects – 2 spaces. My code – my habits. If you want to read it, you can easy convert spaces to tabs.
    Every project must have code guidelines, so all contributors can easy “understand” each other.

    P.S. Search&Replace (or automatic feature) can stop the “holy war”

    • Tim

      When tabs are used for indents (and indents only), it’s safe to search and replace. But spaces are used in data and other whitespace, so a search and replace would destroy that data in horrible ways. Tabs are more semantic!

  • http://santiagorojo.com.ar/ Santiago Rojo

    Totally agree. I hope that trend will change in the future. I had to change my tabs to spaces in order to fit in the coding world.

    Tabs FTW :)

  • http://boltanium.com/ kylebolton

    Decent points, however I challenge you to copy a block of code formatted using tabs and try pasting it into a REPL (for example irb) to evaluate it.

    • Doug

      I doubt that anyone will take you up on your challenge. I also doubt that anyone will answer my question above.

  • http://vorb.de Paul

    Or the ones that prefer Emacs over Vim

    Thank you for the compliment.

  • http://usb3gvn.com USB 3G

    Well, interesting post,
    thanks!

  • Isaac

    Trying to propose the absurdity that indenting != aligning is a sidestep of the failure of your argument. Long live spaces.

    • antred

      You say that indenting is the same as aligning and yet YOU have the nerve to claim that her argument has failed??

  • Norbert Süle

    Totally agreed. It is a pain in the a$$ when you have to adjust some external code you just pasted into your code, because that code is indented with 3 spaces, while yours are not

  • Paul d’Aoust

    Just wanted to offer my support and approval; you hit the nail on the head! I love being able to choose my own tab stops, thank you very much.

  • http://afraser.tumblr.com Adam Fraser

    You might have me sold on this, but Dabblet doesn’t allow me to customize tab-size so I’ll be using spaces in the meantime. ;)

  • http://twitter.com/indexzero Charlie Robbins

    Valid points, but there is one big, important tool that unfortunately does not support customizing your tabs: **GitHub**

    Before I could really consider moving away from soft-tabs as an organization that one would have to be fixed. 

    • http://leaverou.me Lea Verou

      Yes it does, same way as every web app: User stylesheet + tab-size.

  • Pingback: Why tabs are clearly superior | Lea Verou « Grailbox

  • http://twitter.com/sbrandwoo Stephen Brandwood

    Your own dabblet.com is a prime example of why tabs are horrible: they get set to 8 spaces by default.

    • http://leaverou.me Lea Verou

      And your comment is a prime example of why commenting on blog posts you haven’t actually read is horrible.

      • http://twitter.com/sbrandwoo Stephen Brandwood

        I read it and you have some very good arguments. I’m very much on the “I don’t mind, but lets stick to either tabs OR spaces” side of the fence (a.k.a on the fence?).
        The default of 8 spaces per tab is the one thing that always drags me back into the world of spaces, as it bugs me that I need to spend time converting code sometimes.

        • http://leaverou.me Lea Verou

          If you read the blog post, you would have read about tab-size.  Put that in a user stylesheet and you’re done: Every page now has a proper tab width (unless they specified otherwise).

        • http://www.gregboggs.com/ Greg

          Is this only supported in firefox? How about when you click “view source”? I always, always use tabs when programming, because it’s faster to type than 4 spaces.

          However, when I write HTML, especially if I have to use the WordPress editor, an 8 space tab just kills me. I read the post, I read your comments. I read all the comments down to this one… I just don’t understand what this property does for me.

        • http://leaverou.me Lea Verou

          Opera and Firefox at the moment. WebKit is working on it and should be in it soon (I linked to the bug report, you can follow the progress).

          You can use this property in both websites you make, and in user stylesheets so that every other website conforms to it. View Source (at least in Chrome) is also styled by a CSS file, which could have tab-size I guess.

        • http://www.gregboggs.com/blog Greg

          Thanks Lea. I’ve been making websites for years, and I didn’t realize what a user style sheet was until today.  Thanks for the great post. I can’t wait to start using tabs in my HTML again. 

        • Alain

          I love tab for all my C/C++ code (Visual Stuido/Xcode/Dreamweaver) but I can’t figure out how to make Chrome/Firefox/Webkit(coming) apply to when doing ‘view source’. Please add detail steps for those…

  • Rob Steward

    Haha, yes! Vim FTW!

    Seriously, as with many things the true way lies in combining both approaches. As you rightly point out:

    Tabs for indentation
    Spaces for alignment

    …and the world is a better place.

  • mks

    I’m with you. Smart tabs are semantic.

  • http://twitter.com/chuckneely Chuck

    I’ve always preferred tabs for the simple reason that it takes less button hits to get your cursor in the correct place (especially when editing existing code using a non-gui editor such as VIM (terminal) where you can’t point and click to place the cursor). The problem is not all the devs here use the same code editors, in fact almost all of us have a different preference. We’ve simply found it’s easier to set a standard of say, 4 spaces for tabbing than configuring common ‘tab’ behaviour across a range of editors and devices

    • Ar Shui

       For whose who prefer space instead of tab, does you only use one editor or IDE, so you doesn’t know how painful when using different editors/IDEs?  Since NOT ALL EDITORS behave the same when dealing indent with space.

      Don’t Tell me that I should restricted to only ONE EDITOR AT ALL, IT DOES NOT MEAN SENSE TO USE A FULL FEATURED EDITOR FOR SMALL CHANGE (SUCH AS TYPO)

      • http://profiles.google.com/shannon.thrasher Shannon Thrasher

        all the more reason to use tabs and fix your editor to do it the right way, whoever came up with spaces should be — your choice of methodic violence goes here –

  • Anonymous

    Tab oriented languages not withstanding, I think spaces could use a little defense here:
    1. Less space. Any distribution which is concerned about space goes through a packing process before delivery, so this point seems irrelevant.

    2. Can be personalized. Isn’t this the kind of mentality that leads project members to allow their text editor to rewrite tab/space/newline settings? Don’t you conform to the standards of the project you work in? if you merrily let your editor handle it settings who knows what kind of havoc you can create?(answer: the guy who manages the repo knows). 

    3. Better for collaboration. The best thing for collaboration is the thing which creates consistency among collaborators, a view which maps 1:1 to representation is what creates that. If you had said ‘better for balkanization of code by letting each dev set their own standards’, I’d wholeheartedly agree with you.

    4. Certain tools. I don’t depend on auto-spacing any more than you depend on auto-indention. Yes this is a useful feature which save me many keystrokes, but no I would not suddenly regret my decision. In fact often times when I’m in a remote editor or using raw text for something that I am pleased at the uniformity spaces provide. So I would say the person noodling with how their tabs look is they guy depending on a tool. My code always looks right, in any editor, all day(’till some jerk finds a bug). 

    5. Easy to select. I usually band, line or block select, so this drawback isn’t something I’d considered. If I use a select within the editor I can easily select indentation by selecting a string of continuous chars, so again… not something that impacts me. Most importantly, if I walk over to someone else’s editor under a ‘spaces’ regime I don’t see what looks like a ransom note from a third person mingling spaces and tabs without realizing it. For some reason it’s always *that* guy that wants the whole project to switch to tabs. 

    6. Spaces aren’t evil. Spaces mixed with tabs just wreck readability. completely. But on the plus side… this sort of thing leads me to refactor shitty code.

    • Kencrismon

      Glad you did this.  Your responses are spot on.  I am a space guy and your conforming to the standards is well put.  Bottom line.  I do what the coding standards of the project say to do.  Bar none, ALL coding standards in my 20+ years of doing this have been NO TABS; Sorry Mr. Atkins, spaces are to be used.

      Just my $0.02 worth but regardless of the religious side you take, a good blog and some good comments.

      • http://twitter.com/geekbrit Peter Maloy

        Agreed – after following no-tabs coding standard since the late 1980s, I joined a company that insisted on hard tabs in files, then watched the Version Control System go nuts tracking all the tabs-to-spaces-to-tabs conversions as people with different tab width preferences “fixed” misalignments. Just as I had always suspected would be the case.

        • http://leaverou.me Lea Verou

          Which is why spaces should be used for **alignment**. Tabs only for **indentation**.

          Chorus:
          Tabs for indentation
          Spaces for alignment
          Tabs for indentationSpaces for alignment
          La la la

          (I should turn it into a song. It will be a hit)

        • Marcus H.

          And how many spaces for alignment? And what would happen to that magic number when someone who uses a different tab stop views the code? Is this not the bone of contention?

        • http://lea.verou.me/ Lea Verou

          No, not at all. If you use tabs & spaces right, people can view your code with ANY tab size and it will still look fine and things will be perfectly aligned.

        • antred

          “And how many spaces for alignment?”

          What??? What kind of question is that? As many spaces as it takes to __align__ … that’s why it’s called ALIGNMENT. Geez!

        • Daniel Chatfield

          You have clearly not understood.

        • http://profiles.google.com/vivredraco Corey C.

          This complaint is nonsensical. If everyone on the project was following the tabs standard that they were supposed to be using, there would be no “tabs-to-spaces-to-tabs” conversions happening at all. If that was happening, it could only be caused by some set-in-his-ways jackass who insisted on spaces refusing to do as he was told.

        • tasoili

          He’s referring to people that place tabs in order to align – not indent.

          See this:


          function someFunction() {
          var x = 10,
          y = 0;
          }

          The second var, y = 0, should have one tab to indent and 4 spaces to line up the y with the x above it. If you use a tab to indent followed by another to align, it will only line up for people that have tabs represented as 4 spaces.

        • http://danillonunes.net/ Danillo Nunes

          The best thing you can do is to setup your editor to display a tab as 3.7 spaces, so you will not even be able to use tabs for proper alignment, unless you reach a ten-level indentation, which means your code already sucks anyway.

        • Guest

          This is wholly untrue.

          If “var x” is preceded by one tab, and “y” is preceded by one tab and four space, they will *always* match regardless of tabstop.

          You use one tab at the start of each line — so it will always match that far.

          Now you use four spaces on the second line – it will also always match (if you use a fixed-width font), because you are skipping the width of four characters (be they ‘v’ ‘a’ ‘r’ and space or space space space and space).

        • John Runyon

          This is wholly untrue.

          If “var x” is preceded by one tab, and “y” is preceded by one tab and four space, they will *always* match regardless of tabstop.

          You use one tab at the start of each line — so it will always match that far.

          Now you use four spaces on the second line – it will also always match (if you use a fixed-width font), because you are skipping the width of four characters (be they ‘v’ ‘a’ ‘r’ and space or space space space and space).

        • tasoili

          Sounds like we agree?

          I’m saying use tab to indent, then spaces to align. It wouldn’t work consistently if instead you used two tabs preceding the “y = 0;” part.

    • Anonymous Coward

      I think your point of view is slightly skewed.

      2) Personalizing the layout is a non-issue as long as your repository is semantic. Even if your repository isn’t semantic, most decent repos have pre-submit scripts, which you can can fix the formatting for you, and most decent programming editors/IDEs are able to reformat code to your preferences.

      3) The best thing for collaboration is what makes every participant understand the code easier. Getting everybody to the lowest common denominator is counterproductive. If somebody has a problem with 2 spaces indents, but that’s the norm in the project, his productivity will be lowered for no benefit, at least for some time.

      4) This is a non-issue. Tabs and spaces, when used consistently, provide the same consistent view, regardless of the editor you use.

      5) What editor are you using? Thing is, a newer editor will automatically fix up the mess created by older tools mixing spaces and tabs, so that after saving the file it will look consistent across all editors.

      6) You’re right on this one. Still, making some code look readable to me is more difficult if the code uses an indent of five spaces instead of tabs.

      The purpose of code indentation is readability. Using spaces instead of tabs is like any other sort of hard-coding.

      • Anonymous

        2) So you are telling me I should force scaffolding on everyone else because tabs are better? I say they’re not precisely because I need *no* management overhead, project/editor/repository settings or anything else for consistency.

        3) I suppose it’s a difference in perspective: You are focused on comprehension while I am focused on contribution, I prefer to let coding standards facilitate the contributors.

        4) Tabs mingled with spaces (for ‘code prettiness’) produces some pretty horrific layouts, if I use spaces I can make the code as pretty as I want without someone using a different tab stop ‘correcting’ this prettiness. then you’re playing repository ping-pong just tempting conflicts the whole time. WHich leads me to:

        5) if you are using an editor that rewrites your code (line-breaks, tab-stops, etc.) on file-save, you are pure evil. This create such a great rate of change in the repository(unless you force semantic repos/precommit hooks on every project you ever touch) you are almost certain to create conflicts and overwrite other’s work. I’ve heard “No, this will be better, you’ll see” only to trace down reverted bugfixes to checkins of their major feature. Sure this sort of flow *should* work, but in practice all I’ve seen is heartache.

        6) Sweet, we agree! :)

        • Statements and Blocks

          This entire argument is based on the assumption that code should sit in a file as it appears on screen. This flawed assumption causes a “broken by design” implementation that we currently have across the board, as no one has looked at the real cause of the problem (the assumption) vs just bandaiding the symptoms (various display preferences, etc), 

        • Anonymous

          No, it’s based on the assumption files should be edited in the format they are written. The next step down this slippery slope of symbolic code storage is being able to substitute equivalent logic structure, or maybe I layout my files or comments differently than you. maybe I like ant as my build script or maven or fabric or I just get crazy in the shell. The point is a project is an accumulation of these decisions, for better or worse and the aggregate of all these standards is a type of culture, within the code itself. To me, all this talk of I want to look at things ‘my way’ seems totally disrespectful to whoever laid down all that code. Maybe you should be pleading for developers to adopt tabs in new code or for editors that allowed you to use your own formats in translative way to minimize file rewrites and thus project collisions.

          I think your assumption is that indention layout is a trivial user preference, while I say it’s part of the project’s dialect and not something up for alteration.

    • Mecki

      2. When you work on different projects, in different communities and companies, there is no one standard to follow and this is a problem. Project one uses X spaces, company one uses Y spaces, project two uses Z spaces and organization XYZ use whatever spaces. The code looks different all time, you always need to adapt, chances to make it wrong are huge. Or you use tabs and everything is okay: If everyone uses one tab to express one indention level, everyone gets code the way he prefers, everyone is happy and nobody ever needs to adopt to any special standard, at least as far as indention goes.

  • http://twitter.com/jaffathecake Jake Archibald

    Hits the nail on the head. Tabs are for semantic indentation, spaces are for presentational indentation.

    • Br. Bill

      There are situations where this will break if everyone doesn’t use exactly the same tab length.

      • http://twitter.com/skerit Jelle De Loecker

        No, not really. When you split a single statement over 2 lines, you still have to indent them the same way. After this indentation you can use spaces, and then it won’t break.

        • Br. Bill

          You know, I actually take back my previous statement, as you are correct about this. I guess the real problem is that developers rarely do it properly.

  • http://bittersmann.de/ Gunnar Bittersmann

    +1 pro tabs. Using spaces for indentation in code is like using ‘& ‘ for margin on webpages.

    Also annoying with spaces: when clicking on the beginning of a line in the editor, the cursor is anywhere. With tabs: the cursor is at a defined position.

    Spaces for aligning? I’m not sure. The concept relies on monospaced fonts. I prefer proportional fonts in my editor even for coding.

    • http://bittersmann.de/ Gunnar Bittersmann

      Hm, I had tried to post a follow-up… Am I not allowed to answer my own postings? I’ll give it another shot.

      The character entity references got resolved , unfortunely. What I was gonna say is: Using spaces for indentation in code is like using NBSP for margin on webpages.

      To quote Terry Pratchett: “Multiple exclamation marks are a sure sign of a diseased mind.” Doesn’t this hold true for multiple spaces as well? ;-)

      • http://leaverou.me Lea Verou

        Hi Gunnar,
        I see both “Edit” and “Reply” in my own comments, you don’t? Maybe I misconfigured something on DISQUS.

        • http://bittersmann.de/ Gunnar Bittersmann

           I see “Reply”, but not “Edit”. I’d have to register, I guess.

  • Anonymous

    #1 – If you are so worried about space why are you not minifying your output in production?
    #2 – This is why you have coding standards such as PEP8
    #3 – You’re counting on your editor understanding the correct tab key behaviour. If I hit tab here does it indent, or does it change focus from the textarea? I can always enter spaces. So your certain tools point works both ways.
    #4 – Every editor I have ever used has some implementation of smart-tabs to cope with this.
    #5 – So I copy code with tabs and it doesn’t fit me cause I use spaces? Can’t please all the people all of the time.
    #6 – “Enlightened coders”? Sod off.
    #7 – Tabs and spaces, mixed. Now you’re being really stupid.
    #8 – Nope not just pointless detail. For us Python programmers it is a big deal. 

    • http://leaverou.me Lea Verou

      1. Who says I’m not? I only don’t do it in sites targeted to developers, as I believe in View Source.
      2. So that everyone can be coerced into a certain preference, whereas with tabs they could have their cake and eat it too? Cool story bro.
      3. You can always copy the tab character and it’s still one keystroke. Even *pasting* tabs manually is less work than pressing the Space key four times.
      4. Not every editor does and indentation shouldn’t dictate your choice of editor. 
      5. Which is why I said the world would be a better place if everyone used tabs. You could have different tab widths and it still would fit.
      6. Go get a sense of humor, it’s on sale these days I hear.
      7. Haha, I know I’m winning a debate when the opponent starts resulting to childish insults over logical arguments. Well done!
      8. My condolences. 

      • Anonymous

        > Go get a sense of humour, it’s on sale these days I hear

        > Haha, I know I’m winning a debate when the opponent starts resulting to childish insults

        Shall I pick up a spare sense of humour for you while I’m there?

        #1 – So on these sites where you don’t minify size isn’t an issue, so why worry?
        #2 – Yes everyone should follow the same standards. Otherwise you end up with horrible to maintain code, regardless of wether it has tabs or spaces. You do understand the importance of shared standards yeah? Cutting edge or not…
        #3 – Yay for hacks and work arounds!
        #4 – If an editor doesn’t have such a basic function, it is going to have much bigger problems.
        #5 – No it wouldn’t, what about your “awesome” idea of mixing tabs and spaces? If you have different tab widths then your alignment is going to be off all the time. But a space is always the same width.
        #8 – No condolences required. I much prefer working in a real programming language. You have fun marking things up though :)

        • http://leaverou.me Lea Verou

          > Shall I pick up a spare sense of humour for you while I’m there?

          Sure, if you’re paying. More can never hurt. But I doubt you’d have the taste to pick a good one ;)

          1. It’s always an issue, just being open is a more important one.
          2. Of course standards are important, where there actually is a dilemma. With tabs, nobody has to give up their indent width preferences, so forcing a fixed indent on them is pointless coercion.
          4. I assure you, there are plenty of such editors that are widely used and adored. E.g. Espresso by MacRabbit.
          5. Firstly, it’s not only my idea, as you seem to suggest. It’s a widely accepted coding style, as is evident by both the linked articles and some of the comments here. Secondly, you seem to be failing to understand the distinction between indentation and alignment. If you use tabs for indentation only, no matter the tab width, your code is perfectly aligned. 
          8. Your ignorance shows by the fact that you think that front-end languages are limited to markup languages. Or you actually think that JavaScript is “marking things up”? I can’t decide what’s more ignorant.

        • Anonymous

          From the Espresso preferences - http://cl.ly/Doj2

          You can’t make a sweeping statement that mixing tabs and spaces is widely accepted, even the suggestion of it is likely to make a Python developer gag. So perhaps in your language(s) it is, but not all. Where-as if you spaces for indentation as well, you never have to mix :)

          I don’t think all front-end languages are markup languages, that was a joke. I do think they’re (by-and-large) horrible inconsistent messes. But I think the same about many server-side languages (such as PHP). But I don’t think they’re all markup languages. I would still rather gnaw my own arm off than spend my days writing Javascript, but I know it is not a markup language.

        • http://www.bradezone.com Brade

           I appreciated this back and forth :)

          Aaron, I develop in both Python and PHP and I fully agree w/ the author. If anything, since Python depends on indentation as a language construct, it makes all the more sense to use tabs instead of spaces. As Lea said, each developer should be able to quickly specify their own indentation prefs when looking at code.

          As for PHP, I have taken over a couple of projects recently where the author apparently had no indentation standards at all. It’s an absolute smorgasbord of both spaces and tabs and it’s driving me insane >_<

        • Anonymous

          Have you never heard of PEP8?

        • http://leaverou.me Lea Verou

          > From the Espresso preferences – http://cl.ly/Doj2

          I thought you meant preferences for converting pasted indents to your preferred indentation style. Of course every editor has preferences for using spaces instead of tabs. Your point being?

          > You can’t make a sweeping statement that mixing tabs and spaces is widely accepted, even the suggestion of it is likely to make a Python developer gag.

          So? Since when are Python developers a majority in the coding world? And as Brade commented, it’s not even true about all Python developers either. I was talking about C-style languages where indentation doesn’t have meaning (like it does in Python).

          > I do think they’re (by-and-large) horrible inconsistent messes.  But I think the same about many server-side languages

          Apparently you seem to think all languages suck, except maybe Python. Maturity at it’s finest (NOT).

        • Anonymous

          Since when did “many” become synonymous with “all except one”? I was amused however by your comments on my maturity, followed by a large “NOT”. Pot calling the kettle black?

          And I’d like to refer you back to your earlier comment;

          > Haha, I know I’m winning a debate when the opponent starts resulting to childish insults over logical arguments. Well done!

        • arcussinus

          There are ALL KINDS of chemistry sparking between the two of you ;)

    • Anonymous Coward

      You Python programmers … I agree, the nastiest joke you can do on a Python programmer is mess up his indentation settings. But that is your choice. EVerybody likes it, although it’s obviously fragile.

  • http://rachelnabors.com Rachel Nabors

    I am forced to use spaces by coders at two jobs now. I’m not sure why they don’t use tabs and auto-adjust the width. Perhaps it is an adoption issue in the opensource community.

  • http://twitter.com/structerer Martin

     … wow, so many words on so less content

    • Statements and Blocks

      >>words <<content

      • Statements and Blocks

        >> words <<content

  • Anonymous

    Spaces!! Spaces!!

  • Yousuckalot

    You sire, are an idiot.

    • http://leaverou.me Lea Verou

      Maybe, but I’m certainly not a sir (or a sire)

    • http://www.facebook.com/people/Jasmine-Adamson/1461455741 Jasmine Adamson

      Really? What a worthless comment. It’s a little over the top for one, and completely lacking evidence for another. Your opinion is yours to have of course, but it’s completely worthless without an explanation.

      • Brian M

        At least he tried to be polite – but that didn’t quite work, clearly a bit spaced out….. !

      • http://profiles.google.com/shannon.thrasher Shannon Thrasher

        yousuckalot is a spam bot

  • http://twitter.com/bne Ben Miller

    At the risk of being “that guy”, I don’t care either way, just as long as everyone is using the same thing.
    At the moment I’m writing mostly Python which, if you’re adhering to PEP 8, dictates 4 spaces as recommended indentation. 
    It isn’t the spaces or tabs I value, it’s the fact that the code in our team is written in a common style.

  • http://www.facebook.com/arraymac Randy A MacDonald

    Sure, tabs are neater when you need block structures, like loops, or if you need multiple lines for your algorithm.  The ‘dependence on a pre/post processor’ argument is a light one, considering how trivial I find them to build.

  • Brian M

    Use to be in favour of tabs – but have gone across to the dark side :)
    The main reason is for consistency, code layouts should look the same no matter who’s screen or editor you are looking at.
    Not to mention the temptation of coders to randomly use spaces or  tabs depending on their caffeine levels is no longer an issue, so we set tabs to generate spaces -  Sorry I know this is not good for your blood pressure :)As we like to say Code shops are not a democracy they are a dictatorship………

  • Jonny Cook

    I agree 100%.

  • Spacer

    I usually prefer spaces because of formatting/alignment concerns. But your point about using spaces for that, and tabs for indenting, has really hit me.

    Since you also seem to prefer vim, is there a good way or any tricks for editing code with mixed tabs/spaces? Something as easy as setting expandtab, shiftwidth etc. in the .vimrc. That’d do it for me.

  • Frieder

    Couldn’t agree more. Great post.

  • Thaddee Tyl

    I am pretty sure I cannot convince anyone here, and I will always maintain consistency with the coding style that is currently used in the file I’m editing. This being said, the only reason I don’t use tabs is that there is no reason for a single Unicode character, in a monospaced font, to have a size bigger than another character. Tabs undermine the very philosophy of monospaced fonts. That point was not answered to in your article, hence this very comment.

    The way I see it, this issue is very much related to the Markdown vs. Github Markdown conflict. The former lets you put newlines in your paragraph in order to maintain the 80 characters limit, while the latter breaks the paragraph on each line feed.

    Independently of whether the 80-c limit is a good or a bad thing, programmers that want their lines to fit in their editing window implicitly expect everyone to have tabs of the same width. They only enter a line feed if the line they are on goes past that sacred width. Those with a bigger tab width have their line go past the limit. What should they have done? If everybody must count on their editor’s line wrapping, how should the editor know how much to indent the line, so as to please the eyes? Those issues only come up because tabs break the monospace philosophy. Imagine a world without tabs. All those issues would be solved.

    By the way, tabs were invented with certain characteristics. Tabs are not designed to look like eight spaces. Tabs are designed so as to align on the 8th slot, 16th slot, 24th slot, etc. in the 80-slot editor (each slot being able to contain one character, except for tabs, which span across slots). That’s what was called “tab stops”.

    Believing that nobody expects tabs to behave this way still today is wrong. The Go community (based around the programming language) still use this a lot, and their tabs *must* conform to the original idea of a tab (which means that code is indented by 8 slots). They are very vocal about it. (They are very vocal about hating syntax highlighting, too, but that is another issue.)

  • http://profiles.google.com/boctorbill Bill Cernansky

    Your arguments here are about as useful as the arguments for or against CR vs. CR/LF, with one glaring difference. Spaces always work. ALWAYS WORK. The very fact that tabs require special consideration to work across systems, editors, HTML/CSS display, user accounts, source control, etc. makes working with them a nightmare unless you are all alone in your development arena.

    You can keep your tabs and their lousy way of appearing different for every freaking user. Your position is akin to proposing that shoes only come in sizes 4, 8, 12 and 16.  And that if that doesn’t work for you, just change the size of your foot.

    • Tim

      “Spaces always work”? Uhh, no, they don’t. They’re a hard-coded hack that spits on anyone who doesn’t use the author’s preference for indent widths. Spaces “require special consideration” for editors to override the tab key, the backspace key, need to implement their own indent/deindent of spaces, and most don’t even bother fixing the overhead of moving the cursor over these unnecessary characters.

      You obviously paint yourself as an exclusively-Windows user, because CR hasn’t been used by any OS for years now. Mac and Linux use LF. They also have default apps that handle both types of line endings just fine, unlike Notepad.

      Elastic tab size is a feature to allow multiple people to be happy and trade code without conversion, and you label that as a defect with your nonsensical foot analogy?

      • Br. Bill

        You couldn’t be more wrong about me, Tim. But nice try. And if you believe that a tab of 8 and a tab of 2 can ever be compatible just by changing a setting on my editor, then you don’t know tabs any better than you know me.

    • http://profiles.google.com/shannon.thrasher Shannon Thrasher

      how are tabs “not portable?”

      • Br. Bill

        Read the post. If you set tabs at 4 and I set them at 8, then you have TWO TABS for my every one for any code line that is continued from the previous line (if you’re coding for readability), and things get wonky. Seriously. Not portable.

        • Blego

          If you’re running out of horizontal space that frequently, this is the least of your problems.

          And no, you don’t have “two tabs”, you each have tabs and yours are TWICE AS LARGE on your editor. Tabs != spaces. Tabs = ANSI Tab character.

          I would rather have a uniform ONE unit indent character than an ever changing amount of spaces, for the rare event that my lines are blasting past 80 characters horizontally.

        • Br. Bill

          You (and others) continue to fail to see the issue of readability formatting. Even if the lines are not continued, if you are writing for maximum readability by another developer, you will run into this problem.
          It is not possible for me to format code here, so I cannot illustrate the problem for you. But if you are running 4-space tabs and you — for any reason — indent twice past the previous line’s indent, so that something on the two lines matches up, they will only and forever match up if everyone else uses 4-space tabs. For anyone who doesn’t, the careful formatting is useless now.
          I do not see how any experienced programmer has never seen this before.

        • Blego

          You just said what I said. My point is that this is the ONLY occurrence of things not lining up while using tabs for indentation and spaces for aligning. Everything else works no matter what tab setting people have, making it very universal. For spaces to work you MUST have the same as everyone else, making it a very isolated method.

        • Br. Bill

          Spaces are always the same size. If you set your tabbed space settings different from me, that only affects how I enter them. They still look the same no matter what anyone reads them with, unless they use proportional fonts, and that discussion isn’t even worth having.

        • Blego

          Yes your code will look the same to everyone – but not everyone can edit it from the get-go. If someone is a 2 space indenter and you’re a 4 space indenter, there’s a lot of changing to be had. There may be some software for that but then your own argument of aligning comes into play – so that must be changed as well.

          How do you edit another space indenters’ code?

          I feel like there’s a misunderstanding here, because you keep swapping the words tab and spacing and indent around. Are you saying you use the tab key on the keyboard, which then converts to a set amount of spaces via your text editor? Is that what you mean by “tabbed space settings”? And how does me changing the settings affect how you enter them?

        • Br. Bill

          Q. “How do you edit another space indenter’s code?”
          A. However they did it. Smart editors handle some of the smart indentation for me. Otherwise, I bang the spacebar a few times and everything works. My spacebar makes spaces that are the same size as everyone else’s, which I like.

          In response to your other question, yes, “tabbed space settings” is my phrase to describe the autoconversion of my tab key into spaces by my editor. My point is very much that if you have different settings than I do, it doesn’t matter a lick. The spaces will look the same in your editor as they do in mine. Very much not true of tabs.

        • http://lea.verou.me/ Lea Verou

          Seriously, just reading the post refutes that argument. That’s a feature of tabs, not an issue. Just don’t use them for alignment, only for indentation. Let developers see your code the way THEY feel comfortable, not the way YOU want.

        • http://profiles.google.com/shannon.thrasher Shannon Thrasher

          Im not sure how that applies to the term “portable”? But … The argument that your modern editor can’t detect the tab size is moot, no matter what stupidity people throw at it. Also the idea that anyone sets tabs at 8 is kinda silly. Have you really ever seen anyone do this? That’s what you call coding for readability? Two words Code Review. Also with regard to “things get wonky” the same argument applies to space indentation… I hate having to move the cursor over twice or hit delete twice (or four times for God sake!) to get to the next level of indentation, Again, most editors handle that as well, but try editing that space delimited file in notepad? Anyone who says spaces is better has to have a better argument than “they look different for every user” that’s non-sense and a TAB is an IDE setting away from always looking the same no matter where you are. Spaces? Uhm how many do you use again? Spaces are a ploy by the medical industry to give us all carpel tunnel syndrome. Pure evil my friend, pure evil.

    • antred11

      “Your position is akin to proposing that shoes only come in sizes 4, 8,
      12 and 16. And that if that doesn’t work for you, just change the size
      of your foot.”

      Huh?? There is nothing that stops you from configuring your text editor to display one tab as 3, 5, 7 or 9 spaces. It’s not tabs that limit choices, it’s spaces that do that. If you write your code with 2 spaces per indentation level then everyone viewing that code is stuck with that setting. If you had used tabs for indentation instead, everyone could view your code with the indentation width they feel comfortable with.

  • http://www.facebook.com/people/Jim-Fisher/100000137353589 Jim Fisher

    Ever wonder why the make programs to “detab” code? I have never seen one to do the reverse?  The real problem is that in my line of work, the indentation is dictated for the project by a coding standards document. Many editors allow you to define the tab points but they often revert to their default and use of another editor or printing the code or cutting a snipit to include in a document is sure to be messed up. I have terabyte HDs so no need to sweat the extra space… it prints fine, pastes into a document fine and looks the same in any editor.

    • Tim

      It’s trivially-easy to replace tabs with spaces. On the other hand, it is a pain in the ass to convert space indentation back the other way into tabs. Tabs are semantically more valuable than hard-coded spaces.

      Nevertheless the “expand/unexpand” unix commands already exist to do those conversions, so you obviously haven’t looked very hard.

  • Dale King

    Spaces are 100% portable, tabs are not. End of  discussion.

    • http://leaverou.me Lea Verou

      tl;dr? Poor thing.

    • http://twitter.com/skerit Jelle De Loecker

      They are, people just use them wrong.

  • JW

    You’ve concentrated on some irrelevant arguments (like saving disk space, who cares these days?), but have missed some of the key advantages of tabs:

    1) Tabs reduce typing effort (Yes, editors will insert groups of spaces automatically when you press tab, but cursor movement and deletions must be done one at a time).

    2) Tabs make typing consistent – inserting/deleting/moving past an indent is always a single keypress. With spaces, one keypress creates an indent, but then you need to press delete an *indeterminate number of times* to remove the indent. That means I have to watch what I’m doing and press delete until my cursor lines up with the previous line, or (3) occurs.

    3) Tabs are indivisible. With spaces it is easy to end up on a non-tab column, and then you have either messy code or waste time tidying up the indentation. Tabs eliminate this problem by “snapping” code to the correct indentation column automatically.

    • http://leaverou.me Lea Verou

      All very good points, but I thought editors mask these issues? I thought only web editors have them, due to their inherent simplicity. I’ve always used tabs all my life so I don’t know how well editors manage to hide the fact that they’re N characters instead of one.

      • http://profiles.google.com/shannon.thrasher Shannon Thrasher

        Editors try to mask these issues but poorly imo. Something catches a double space or whatever and instantly you have a mess of tabs and spaces. some editors have an auto indent feature, but the varying spaces used by developers seem to confuse it. Also along those lines, tabs can be changed to look like two spaces which voids the “I have to see everything in 80 columns” argument. I’m going to continue to use tabs, these three points alone sell it. Honestly when I look in the sources, it seems I’m the only person that cares anyway. :)

  • ozmosys

    Couldn’t disagree more! Why infect your source code with non-printable characters, when any self respecting IDE can reformat to suit whatever coding standard anyway (we adhere to the language’s published coding standards so this is not an issue).

  • barBill

    Agree. Setting up a tab helps to avoid fighting for space at the bar.
     *Hic.

  • Pingback: PAYcast 39 » PAYcast

  • Pingback: Indentation: tabs or spaces?

  • http://twitter.com/24daiting 24daiting

    Excellent article, thank you very much. We must try!

  • Richard Lopes

    At last someone that feels the same way I do about spaces and tabs ! I had to recently switch back to spaces but it cause me more trouble than anything. Will soon go back to tabs only for sure.

  • http://www.orizens.com/ Oren Farchi

    thumbs up Lea. I also find Tabs to be my default standard – because of:
    * selecting with keyboard is easier
    * less characters :)
    * “feels” materialistic and clean – also in some way – it forces these
    * can be customized with its width (any number of spaces)

  • Pingback: My Coding Style and Guidelines | @drublic

  • http://www.makestuff.eu/ Chris McClelland

    Here’s my cat, Tabitha. She prefers tabs, no question about it.

  • http://pulse.yahoo.com/_G6XUHJRLMIRMTJSWLLAIJDM4WI Admiral Ackbar

    if you work with multiple developers you soon find out that tabs in the code make the code hard to read. over the last 35 yrs of developing spaces always won.

    • antred

      If you mix both indentation styles in the same file then of course everything gets messed up and hard to read. If you use only tabs to indent (or even only spaces) then everything will be just fine.

  • Mecki

    I totally agree. Tabs are far better than spaces and most people arguing about it failed to understand the difference between indention and aligning. Tabs are for indention, spaces are for aligning, it’s that simple.

  • theMountinman

    The problem with tabs is that they aren’t characters, and very few fonts represent them consistently. If source is moved across media boundaries, tabs will INEVITABLY fuck up it’s appearance. It also confounds parsers. I NEVER have that problem with spaces. Since IDE’s can be configured to auto indent the number of spaces that is standard for your shop, using spaces isn’t laborious (I’ve never found it to be so even without auto indent).

    In my experience, the people who bitch about spaced indentation don’t care how the code looks and are simply lazy.

    The bottom line is that argument is like religion: everyone has their own view, and NO ONE is right. I don’t begrudge anyone their view as long as they don’t try to push it on me.

  • Br. Bill

    Even though I’m anti-tabs, one thing that makes my life so much better in an environment where you can’t prevent people from using whatever they want: showing tabs as visible characters. Komodo does a fantastic job with this, and display tab characters is on all the time. Super useful.

  • Nasga

    I agree with hard tabs (except about space, because no-ident style will win uppon both).

    But most languages recommends to use spaces :
    – Python with PEP8
    – Php with PSR-2
    – Node js with npm coding style.
    - Ruby with https://github.com/bbatsov/ruby-style-guide#source-code-layout

    - Many more…

    Then why keep hard tabs in codes ?
    Spaces are really easy to manage with vim and most of your arguments could be cleared by a descent vimrc…

  • AnonymousForAReason

    Another potentially valid discussion ruined by the author’s insistence on assuming anyone who disagrees didn’t read the article in the first place. Egotistical writing with a splash of superiority complex. Go on, tell me I didn’t read the article (twice). I dare you.

    • http://lea.verou.me/ Lea Verou

      Well, if somebody replies with an “argument” that I addressed in the article, there are two obvious explanations: Either they didn’t read it, or they’re dumb. I sincerely apologize for assuming the former; judging by this comment of yours, it’s clearly the latter.

    • antred

      You’ve either not read the article, failed to understand it or you’re so set in your ways that you’ve decided not to let reason get in the way. There’s no other explanation for why you would still favor spaces over tabs for indentation. But don’t worry, 80% of all people seem to share your condition.

  • http://www.facebook.com/reinierk Reinier Kaper

    I don’t get the “alignment” argument, since that’s why the tab character was invented. You could also simply battle it by not using a space after your declaration, but a tab. Of course no one does that ;-)

    I’d have to say I still prefer spaces for this reason. I find it more predictable to work with spaces, especially when stuff gets aligned like the vendor prefix example you have.

  • Brandon Frohs

    CodeMirror supports tabs (and doesn’t convert them to spaces by default… or at all, AFAIK). Perhaps you’re talking about an older version of CodeMirror? Or maybe the site/app that embeds CodeMirror is doing this? See http://codemirror.net/demo/visibletabs.html or http://codemirror.net/mode/markdown/index.html.

  • http://moox.fr/ MoOx (Maxime Thirouin)

    I also prefer Tabs for the same reason as explained. However, I respect others choices, so I encourage people to use .editorconfig ( http://editorconfig.org ) and you should too.

  • nateabele

    Fuckin’ nailed it. Thanks for compiling such a comprehensive list of why tabs are awesome.

  • http://twitter.com/liversedge liversedge

    I don’t care if you use tabs or spaces for indents.
    JUST DON’T USE BOTH.

  • http://blog.nuclex-games.com/ Markus Ewald

    I disagree 100.0% on every single point made. No offense intended, just a perfectly contrasting view :)

    In my opinion, the file size is completely irrelevant, personalization is actually a drawback because I can no longer ensure horizontal scrolling isn’t needed, collaboration is the same point made again (and there’s more about formatting that can get in the way than just tabs), tabs are completely tool-dependent, selection with tabs in code is a bitch (no more linear cursor movement), copy & paste still has different coding style and indentation, the web _is_ an issue regardless of obscure expert settings in selected browsers and mixing in spaces for alignment is the final nail in the coffin (try mixing tabs with spaces in Python where indentation has meaning).

    I laid out my own reasons for why nobody should ever use tabs in detail here: http://blog.nuclex-games.com/2013/02/why-you-should-indent-with-spaces/

    • Brian m

      Spot on! But everyone to their own, except on any projects I’m managing, I’ve seen tabs really messing up the the dev environment. Only saved by tab to space converter and a lot of clean up editing. Crazy to use tabs, their only consistency is their lack of it!

    • http://lea.verou.me/ Lea Verou

      I can no longer ensure horizontal scrolling isn’t needed

      You can’t ensure that anyway, it depends more on the window and screen size than your code. Also, another developer might prefer better readability than no horizontal scrolling, why not give them the choice?

      tabs are completely tool-dependent

      If you think tabs are tool-dependent, try working with spaces in an editor with no indentation conveniences. You’ll almost certainly end up using inconsistent indentation, like 2 spaces here and 3 there. When working with spaces you depend on your editor to mask the fact that you’re using multiple characters instead of one. It even happens with proper editors, as they’re not perfect. Most code I’ve had to edit that was space-indented had this.

      copy & paste still has different coding style and indentation

      Only for those who use spaces. For those who use tabs, regardless of tab width settings, it will match their style.

      the web _is_ an issue regardless of obscure expert settings in selected browsers

      If you don’t know what something is, it’s wiser to google it up than to try to pretend you know. tab-size is not a setting in browsers, it’s a CSS property you can add to your code and it will work in every browser that supports it (practically all browsers in use today except IE).

      • http://blog.nuclex-games.com/ Markus Ewald

        > You can’t ensure that anyway,

        I can and do. Anyone who arranges his IDE to display 100 characters can view my code without any horizontal scrolling. Most monitors at typical font sizes would manage at least 200 characters, leaving enough room for panels, choice of font size, etc.

        You statement seems to associate long lines with better readability. In my view, overlong lines are the very antithesis of readable code. You have to reach for the mouse, scroll right, remember what you’ve seen, scroll back, locate where you’ve left off. Thus, breaking the line is always preferable to me.

        > You’ll almost certainly end up using inconsistent indentation, like 2 spaces here and 3 there

        I’ve been programming professionally for 15 years and I can honestly say that never happened to me nor have I ever seen any space using code where that happened. Perhaps a simple check of a few Open Source projects would be worthwhile, maybe there are cases of that happening.

        Regarding the editor “masking” spaces – from my point of view, tab are what editors have to mask and hide:

        - With spaces, when you’ve indented by 2/4/8 columns there are 2/4/8 very real spaces that aren’t masked or hidden in any way. Or are you referring to convenience features, like going back to the higher indentation level with backspace or padding new lines upon pressing return? They’re like line a rectangle drawing tools in a bitmap editor to me, I wouldn’t want to add a special color that becomes 8 pixels or something to bitmaps.

        - With tabs, you see 2/4/8 columns, but it’s only 1 real character. To achieve linear cursor movement, the editor has to act as if it was possible to move around inside the tab character (and turn it into spaces if you actually start to type inside a tab). Or alternatively, let the cursor jump over the tab causing a sudden cursor speedup that I at least greatly dislike.

        > Only for those who use spaces. For those who use tabs, regardless of tab width settings, it will match their style.

        I’m talking about copy & pasting code from another library. Chances are, it uses a different brace style, different casing, that the code was placed at a different indentation level in the first place, and so on.

        Copy & paste (as bad as it is for programmers) that takes place within the same codebase has the same indentation rules anyway, but I accept that tab users that work with different tab widths (which I consider a drawback due to the line length and alignment issues, as I’ve laid out in my post) will at least not mess up the indentation (unless they aligned with tab characters, which is likely to happen if the code had aligned lines, from my point of view).

        > If you don’t know what something is, it’s wiser to google it up than to try to pretend you know.

        No need to get personal or to assume malice.

        There was or is an obscure setting in Firefox that lets users configure the tab size, reachable via the expert settings (enter about:config in the address bar). I last used that with Firefox 3 and all I can dig out now is devtools.editor.tabsize, which doesn’t sound like it would apply to normal page display.

        I must have skipped over your mention of CSS3 and concluded that you meant aforementioned browser setting (because it was once mentioned to me by another tab advocate). For that I’m sorry.

        As far as I can see it has already made its way into Firefox, Opera and Chrome. If it eventually reaches all major browsers, it might get tabs to display just as well as spaces (though leaving the alignment issue unsolved).

      • Doug

        A developer here brought up inconsistent indenting. As long as the 2,3, or 4 spaces is consistent within the same block, I don’t care too much, that is, I still much prefer spaces over tabs.

    • crashfr0g

      You can mix tabs and spaces in Python, so long as you’re doing it in the only place where you should be doing it – using Python’s implicit line joining to prevent 200-character-long function calls. And you should still be tabbing over to the appropriate level of indent, then adding spaces to make the arguments line up.

    • http://lea.verou.me/ Lea Verou

      1) tab-size is not a browser setting, it’s a CSS property, so your whole counter-argument on that is utterly ridiculous and makes you look like an ignorant fool.
      2) You cannot ensure horizontal scrolling isn’t needed anyway, because you don’t know what screen and window size your code will be viewed in
      3) Tabs are not tool dependent and I’ve never seen them interpreted as “insert X spaces here” ANYWHERE. If there is some obscure app doing this, it’s a bug.
      4) The linear cursor movement thing doesn’t sound like a real problem. OCD much?

  • arcussinus

    Listen… I am aware that I am about to make a dangerous assumption, but seeing your complete devotion to this kind of discussions simply makes me wonder. If you have studdied (and finished) computer sciences at mathematics faculty and were engaged in a development of s e r i o u s software I can, with 100% certainty, claim that you would not even think about “code formatting” or “tabs vs spaces”… instead, you would be consumed by algorithm development, theory of computation, construction of predicate models and counter models… When I read source material, I really don’t give a d a m n about formatting, as long as there is a n y indentation and one instruction per line. Oh, wait, that’s what separates computer scientists from “coders”. I guess coders are needed. After all, we do require dactilography experts with an ego trip. But, just to think how a simple call to a simple program like GNU Indent… Anyway, this read was fun. I wanted to watch a movie while my better half was at her dance nigh, but I somehow ended up here :P

    • http://lea.verou.me/ Lea Verou

      So basically, what makes someone a computer scientist is their disregard for code formatting. Thankfully, I’ve met many great computer scientists who have passed the cocky stage of considering certain things below them and better left to the CS plebeians. You still have way to go. I hope you’re young, otherwise, there’s not much hope left.

      PS: I have a hard time wrapping my head around the idea that a real Computer Scientist (or any kind of scientist, really) would make such logical leaps and assumptions with little data, especially with “100% certainty”. LOL, good story bro.

  • http://twitter.com/psynaptic Richard Burford

    I’m totally with you that tabs are superior to spaces but I’m stuck in a world where spaces are demanded and most people around me (e.g., colleagues, open source community, etc.) think that using 2 spaces for indentation is preferable and more compatible across the various mediums code can be consumed. Even if I did convince enough people that tabs were a better idea and that we should switch, we’d have to convert a huge codebase to use tabs, thus losing a lot of git blame information, and that’s not even considering all the sites out there that use the project, or legacy codebases for that matter.

    Even getting people to properly follow coding standards is difficult. As you mentioned, poorly named variables are very annoying. As is not using the standard format for inline documentation (or lack thereof), poor code style (even simple things like avoiding writing long, dense blocks of code without any whitespace to logically separate sections), and not creating reusable/abstracted code. At the end of the day, these things only truly matter in terms of readability, maintainability, and flexibility, which are important factors in their own right, but are seemingly less important than the fact it is fit for purpose (it works, is secure, performant, and so on).

  • Doug

    So, I know I can configure vim so that a tab displays 2,3, or 4 spaces. How do I configure putty so that when using grep/sed/awk, a tab expands to less than 8 spaces? This is a major annoyance of mine.

    • Doug

      In case the above comment was too subtle, let me rephrase…tabs are inferior, end of story.

  • francois

    Hi,

    I agree with you on the fact that tab is better for indentation than space.
    However, you can also use tabs to align, within a line: true, it takes a bit more effort than just using spaces, but I find the benefits sizeable.
    Please check out my article:
    http://francoishill.fr/tab_space_use_both_know_difference/

    Regards

  • http://usb3gvn.com/ USB 3G

    We hope that you find this information useful and look forward to assisting you in the future. Thank for this support.http://usb3gvn.com

  • Pingback: Tabs or spaces? I use both. | JHH's blog

  • http://www.nurasto.com/ Dityo Nurasto

    I am using tab because sometimes I wrote my code using non-monospace fonts like Times New Roman or Myriad Pro. If bored to death, Wingdings.

  • Matt Inglot

    Hell yes! :D Thanks for the great article, I am updated our coding standards at Tilted Pixel and will be citing this for why we use tabs.

  • Max

    Big thanks for the article. Tabulation it is cool. From Russia with love.

  • Jader Feijo

    Fully agree! Tabs rule!

  • Chris

    Pretty much the argument for tabs boil down to just, “You can choose your own indentation” Everything else is just stupid (Makes the file smaller by a few bytes on my 3TB hard drive, wow!)

    Except this too is really a minor point. You might have a preference but it’s not that bloody hard to change.

    The reason spaces are better is because, as you pointed out you should use spaces should be used for alignment. In theory, using tabs for indentation doesn’t screw this up, but in practice, it leads to people using tabs in their alignments. It’s just much easier to just never use tabs.

    • http://lea.verou.me/ Lea Verou

      It’s not the 3TB hard drive only, it’s also the bandwidth when people download the file, in web dev at least. Yes, you can always minify, but most people don’t minify everything.

      Also, is your argument really that spaces are better because people are lazy?

      • Chris

        My argument is people make mistakes. The benefit of being able to change your indentation is minimal at best. The advantages of aligning your code is huge – more readable, clearer intent, reveals redundancy, more maintainable. By using tabs, you’re making a big sacrifice for minimal gain.

        Most IDEs to indent with tabs means the tab key will always insert a tab character.

        Most developers don’t use visible white space and if you want to align something which is 10 spaces away, it’s faster to hit the tab key a few times instead of hit space ten times. Doing this they don’t realize they have inserted tabs.

        By always inserting spaces you eliminate this problem completely.

        • antred

          Unless your shoe size exceeds your IQ it would be almost impossible to get confused by a concept as simple as “tabs to indent, spaces to align”.

        • Jonathan Neufeld

          I think you have nailed the fundamental problem here, well done.

          Now onto tackling network effects with our new-found wisdom.

        • Robin Munn

          And yet I see the results of such confusion all the time. In theory, theory and practice should be identical. In practice, they’re different. In theory, tabs would be ideal because they would let everyone use their preferred indentation. In practice, they cause more headaches than they’re worth, because almost everyone forgets to use them correctly.

      • Chris

        I recently wrote up my reasons in full – https://github.com/cpmcgrath/codealignment/wiki/Tabs-&-Alignment

  • aka

    In erlang how to propertly use tabs to do this
    1.function_name_which_is_usually_quite_long(argument1, argument2, argument3,
    2. argument4, argument5, argument6) ->
    3. body.

    In spec there are also types of those arguments, which usually are longer than names itself) which makes very long indent.

    in line 3 – I understand that I should use tab, what about line 2?
    You say spaces?
    But life is not ideal – there will be somebody who forget/will be too lazy/ to do it.
    The same thing is using spaces for alignmnet – there will be somebody who will do it other.

    Second arguments – speed of editing.
    What if there will be need to add argument between 4 and 5, and 6 must go to other line. Then we can again align this by putting horrible amount of spaces. Or just use tabs, to hit less, and because editor expands them on spaces we will be quicker.

    Spaces are portable. Tabs are not.

  • jasonm23github

    > Or the ones that prefer Emacs over Vim
    …sigh.

    Someone needs to try Evil mode in emacs.

  • Bianchi Mario

    “Tab” stands for tabulation and its real meaning was moving the cursor on a table.
    There are 2 kinds of tabs. Horizontal (t) and Vertical (v) in the ASCII table.

    Are not invented to be converted in space as you mention here

    “Assume for some reason you want to select all indents and double them or
    convert them to spaces. This is very easy with tabs, because that’s
    their sole meaning. Tabs were invented for this sort of thing.”

    neither for indentation.
    That said, could be a good alternative to space.
    Cheers!

  • Jonathan Vitela

    “For example, coders that don’t name their variables properly. Or the ones that prefer Emacs over Vim”+1 For that!

  • tab-lolz

    Seriously, mixing tabs and spaces? Thats the answer? And they take up space? Code compile you know, or minify. Real programmers know that. Just admit it, have you ever encountered a problem reading a space indented source? Now what a about a tabs indented, how much time do you usually have to spend on “customizing” it? Insta-win for spaces.

  • Erik van der Neut

    Lea, I agree with you 100%, but I would take the “Tabs take less space” section out, as its irrelevance weakens your argument.

  • Erik van der Neut

    I don’t believe that the indentation level with spaces (e.g. 2 versus 4) can be saved on a per-project basis in Xcode. Thus, simultaneously working on projects with different spaces-indentation standards forces you to change this setting each time you switch projects. A nuisance that tab indentation would fix as well.

  • Dave Stewart

    I can’t tell you how much I love this article. I may even put it on the back of my business cards!

  • Pingback: Convertir facilement les espaces en tabulations avec Sublime Text | feub.net

  • Andre Z Sanchez

    I use spaces because tabs are annoying to traverse since they take more horizontal space. Spaces are more consistent with other characters. If it weren’t for that I wouldn’t mind using tabs.

  • Marcelo

    Tabs is all about respect others preferences and keep your code clean. I really don’t know why there are people who still uses spaces as “Standard”

  • Lutz

    Just found your blog post after I read a comment on twitter about indenting :) I like your convention to use tabs for indentation and spaces for alignment (e.g. vendor prefixes in css or the var statement in js). Nice to read code style recommendations that differ from http://javascript.crockford.com/code.html :). Kudos