Slashdot Mirror


400,000 GitHub Repositories, 1 Billion Files, 14TB of Code: Spaces or Tabs? (medium.com)

Here's a debate that refuses to die: given a choice, would you rather use spaces or tabs? An episode of Silicon Valley last season had a bit on this. Now we have more data to analyze people's behavior. A Google developer has looked into 400,000 GitHub repositories -- 1 billion files, 14 terabytes to find that programmers with interest in specific languages do seem to prefer either tabs or spaces. Spoiler alert: space wins, like all the time.

56 of 391 comments (clear)

  1. Tabspaces? by PCM2 · · Score: 5, Insightful

    Yeah, OK, I get it. Spaces make it easier to cut and paste your code into whatever and have it look the same. But does anybody seriously type all those spaces? You don't just set the Tab key to expand to spaces?

    --
    Breakfast served all day!
    1. Re:Tabspaces? by Anonymous Coward · · Score: 4, Insightful

      Any IDE can be configured to use spaces instead of when you indent.

    2. Re:Tabspaces? by somenickname · · Score: 2

      I imagine that most people have their editor set to do smart spacing. The editor is smart enough to properly line up the next line based on the content of the previous line. So, it's not really onerous to use spaces and has the added benefit of being unambiguous.

      Amusing anecdote: Some very old Unix software is fanatical about using tabs. Not because of style considerations, because it's old enough that the extra disk space consumed by using spaces was unacceptable when the software was first written.

    3. Re:Tabspaces? by Austerity+Empowers · · Score: 3, Insightful

      But does anybody seriously type all those spaces? You don't just set the Tab key to expand to spaces?

      Not unless you are using notepad. Everything from vim to atom.io will let you choose hard tabs or spaces, almost all of them know to use hard tabs in makefiles. All of them can auto-indent too with either hard tabs or spaces.

      I worship the religion of spaces, but the religion of spaces still derives from the pantheon of indentation, we all use the tab key but will absolutely crucify anyone from the other religion.

    4. Re:Tabspaces? by Viol8 · · Score: 2

      " The editor is smart enough to properly line up the next line based on the content of the previous line."

      That is one of the most annoying things an editor can do IMO (and if someone has put it as a default in the global .vimrc they need to die a slow painful death). If my next line is in an outer block it means i have to delete the damn indentation which is a lot more labour intensive than putting some in in the first place!

      Also with tabs I can change the indentation width to suit my needs, with spaces I can't without doing a global search and replace which will probably fuck something else up (eg spaces inside a string).

    5. Re:Tabspaces? by PCM2 · · Score: 4, Insightful

      Do you really think people using spaces are sitting there tapping the spacebar 12 times for every line?

      Well no, so that's kind of my point. It's really tabs for everybody, because nobody has given a shit about the ASCII contents of text files for years.

      --
      Breakfast served all day!
    6. Re:Tabspaces? by EndlessNameless · · Score: 2

      What is this tab-expansion black magic that you're talking about?

      You know, this mystery thing that Silicon Valley apparently knows nothing about.

      Otherwise known as "the feature which makes their entire analysis meaningless".

      --

      ---
      According to the latest ruleset, this post should be modded as Vorpal Flamebait +5.
    7. Re:Tabspaces? by johnw · · Score: 3, Insightful

      That is one of the most annoying things an editor can do IMO (and if someone has put it as a default in the global .vimrc they need to die a slow painful death). If my next line is in an outer block it means i have to delete the damn indentation which is a lot more labour intensive than putting some in in the first place!

      Your average editor which does auto-indentation like this generally has enough smarts to realise it needs to go back a level when you finish a block. You keep typing and your desired and configured indentation just happens.

      Even if it didn't (and why would you use an editor which couldn't manage it?) it would still be less work to reduce by one level of indent than to insert N-1 levels.

    8. Re:Tabspaces? by lgw · · Score: 2

      Well no, so that's kind of my point. It's really tabs for everybody, because nobody has given a shit about the ASCII contents of text files for years.

      Except for all the version control tools and diff viewers out there that still aren't very sophisticated. This is why we insist people normalize to spaces (and normalize line endings). You don't want that shit in your way when you've got a cryptic, urgent bug at 3 AM.

      --
      Socialism: a lie told by totalitarians and believed by fools.
    9. Re:Tabspaces? by Hognoxious · · Score: 2

      I do. I find the rat-atat-rat-atat-rat-atat-rat-atat very therapeutic.

      --
      Confucius say, "Find worm in apple - bad. Find half a worm - worse."
    10. Re: Tabspaces? by PCM2 · · Score: 4, Insightful

      Also, please stop moving the goal posts, first you said "text files" and now you suddenly shift to "source code files". Not cool.

      Sorry, I forgot about the combination of not reading the stories and the autism spectrum. My bad.

      --
      Breakfast served all day!
    11. Re: Tabspaces? by gfxguy · · Score: 5, Interesting

      Python is my go-to scripting language when possible, but it's the one thing about it that bothers me - the anal retentive way it forces you to follow Guido's formatting standards. Yes, there is some choice, but when you figure out that tabs make more sense you become an outcast in the python community.

      --
      Stupid sexy Flanders.
    12. Re:Tabspaces? by Z00L00K · · Score: 2

      And then you can use an auto-formatter in the editor that cleans up stuff for you and replaces any tabs for indentation with spaces.

      A tab is usually 8 spaces, but the editor may be configured otherwise. For small programs the 8 space tab is good enough, but as soon as stuff grows it has a tendency to cause the need for a very wide screen and refactoring help to break down things.

      So I imagine that if you look at the size of the program you will see that in small programs the tab is more common than spaces for indentation. Often because you can live with using notepad, edlin, vi or even "cat > src.c" for the small snippets.

      --
      If builders built buildings the way programmers wrote programs, then the first woodpecker would destroy civilization.
    13. Re: Tabspaces? by gfxguy · · Score: 2

      The problem is you're confusing languages and editors, and it depends on the editor, and yes, after it inserts "x" number of spaces when I hit the tab - and then I need to unindent, it's annoying. Why on earth so many programmers decided to standardize on spaces instead of tabs is baffling until you understand that they are anal retentive nut bags who insist on "x" number of spaces per indent with no choice.

      --
      Stupid sexy Flanders.
    14. Re:Tabspaces? by hermitdev · · Score: 2

      This is why I generally prefer to keep hard tabs for indentation, and uses spaces for alignment. Different people have different preferences. I've seen 2, 3, 4 and 8 in the wild. This really sucks when you have all 4 types working on the same project. Any decent editor (I'm scowling at you, notepad) allows you to configure the rendered size of a tab.

    15. Re: Tabspaces? by dfghjk · · Score: 4, Insightful

      As objectionable as it sounds, python's odd approach to white space doesn't present problems in practice nor does anyone using any reasonable editor have problems with "tabs vs spaces" in Python. It's a non-issue.

      The real violator is make. It actually requires tabs where spaces would otherwise work. It is an actual problem yet no one claims make is for "faggots" except perhaps AC a-holes like you.

    16. Re:Tabspaces? by Z00L00K · · Score: 4, Interesting

      That's when it's time to run the code through a formatter an check it in again.

      --
      If builders built buildings the way programmers wrote programs, then the first woodpecker would destroy civilization.
    17. Re:Tabspaces? by Cederic · · Score: 2

      Wait? Automated prettify-on-check-in isn't standard these days?

      Shit, had that set up 15 years ago and felt embarrassed about taking so long then.

    18. Re: Tabspaces? by viperidaenz · · Score: 2

      TAB is short for "Horizontal Tab", which is code point 9 in the ascii table.
      Space is point 32

      Python has no problem with tab characters for indenting, as long as the source file consistently uses the tabs or spaces.

    19. Re: Tabspaces? by allo · · Score: 2

      > Python has no problem with tab characters for indenting, as long as the source file consistently uses the tabs or spaces.
      You don't need to. You can indent one line with 1 space and the next one with 1 tab.
      If you want to, you can make debugging the hell for the next person, when the less indented 2-space line is logical indented to the 1-tab line before.

  2. I always use tabs... by QuietLagoon · · Score: 3, Funny

    ... except for the times I use spaces.

    1. Re:I always use tabs... by AmiMoJo · · Score: 3, Insightful

      It's all these Java and HTML heathens skewing the results. If you look a C files the majority use the correct tabs for indentation and optionally spaces for alignment later.

      If god wanted us to use spaces for indentation he wouldn't have made keyboards with tab keys. Also, they reduce wear on your space bar and fingertips.

      TABS!

      --
      const int one = 65536; (Silvermoon, Texture.cs)
      SJW, n: "Someone I don't like, and by the way I'm a fuckwit" - AC
  3. what he said by cellocgw · · Score: 2

    You may "use" tabs, but plenty of editors are set to translate the tab into N spaces.

    Worse, plenty of editors import text documents and **change** the tabs to N spaces whether you wanted to or not.

    Usually this results in a totally garbled python script.

    --
    https://app.box.com/WitthoftResume Code: https://github.com/cellocgw
    1. Re:what he said by gaudior · · Score: 4, Insightful

      Usually this results in a totally garbled python script.

      This is why I avoid Python. Program logic should not be governed by invisible things.

    2. Re:what he said by TangoMargarine · · Score: 4, Informative
      --
      Unity? Screw that: XFCE. Slashdot Beta? Screw that: SoylentNews. Australis? Screw that: Pale Moon. UX developers DIAF
  4. The article conveniently ignores Python by ribuck · · Score: 2

    The article conveniently ignores Python, a 100% tabbed language.

    1. Re:The article conveniently ignores Python by Anonymous Coward · · Score: 4, Informative

      Wrong: https://www.python.org/dev/peps/pep-0008/#tabs-or-spaces

    2. Re:The article conveniently ignores Python by ausekilis · · Score: 2

      Python isn't a "tabbed language" it merely relies on levels of indentation. Consistent type/count of whitespace in front of code is used to differentiate namespaces. It could be 'n' spaces or 'n' tabs, just prepare for pain if you mix them within a file.

    3. Re:The article conveniently ignores Python by swillden · · Score: 2

      As I said above, PEP8 only applies to the Python project, not all projects written in Python. There is no recommendation for Python code other than consistency.

      PEPs are also generally considered good style recommendations for other Python code.

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
  5. Doesn't matter who "wins" by LordLucless · · Score: 4, Insightful

    Popularity is a poor measure of quality. Otherwise McDonald's would be Michelin starred.

    --
    Just because you're paranoid doesn't mean there isn't an invisible demon about to eat your face
  6. Spaces are for people who don't understand tabs by Viol8 · · Score: 5, Insightful

    The whole point of a tabstop is you can change its width so a file can be indented to the preference of the person reading/editing it (set ts=[width] in vi). With spaces you're stuck with the (often poor) indentation the author chose who is essentially saying "Fuck you, you're going to read the code indented the way I want, not the way you want"

    1. Re:Spaces are for people who don't understand tabs by johnw · · Score: 4, Insightful

      It's a nice idea in theory, but it's never worked - nor is it the point of tabs.
      If all indents were always solely at the beginning of a line, and always an exact multiple of whatever N you've chosen then it might have a chance, but they aren't and so it just breaks.

      Don't mess with the size of a tab character - you'll just cause pain.

    2. Re:Spaces are for people who don't understand tabs by cfalcon · · Score: 2, Informative

      > a file can be indented to the preference of the person reading/editing it

      No, fuck that. I shouldn't have to mess with my editor to get sane spacing. Code is text, not binary. Get the binary out of the code. What if my editor isn't able to do that, and what if I need to use a text mode or command line? Fuck all that hassle.

      And to flip it: if you really need to see it with some OTHER number of spaces than are actually there, I bet there's a text transform you could apply to the spaced file too. We don't need to start putting tabs places to get this.

      What if you EVER need to indent something, but less than the full amount? You are outta luck with tabs.
      What if you are writing something where you want a character to exist directly underneath another, but one is preceded by non-whitespace, and the other by whitespace? With spaces, you just do that, with tabs, fuck you.
      A tab means very different things to different programs. Unless your code is just for you, you don't know the future use case of future programmers. You don't know if it will be output in a shell, in an editor where tab is interpreted, not as a number of spaces, but as instructions to go to a tab stop (you know, the actual intended use of tab in formatting), or as some other thing completely.

      But really its simple: a space is a space. A tab is a formatting instruction that every coder from that point must deal with in every display device that the code is viewed on, taking it from a simple text file to some binary file that requires everyone tweak settings for, as well as the unspoken condition that certain types of formatting become impossible (line A has a standard indent followed by the word "Quintuple", line B is supposed to have a character underneath the "p"- can't do that with tabs and have it be display independent anymore)... Tabs work for the tabber, and the tabber alone. Spaces work for everyone.

    3. Re:Spaces are for people who don't understand tabs by serviscope_minor · · Score: 4, Insightful

      Ick no!

      Use only tabs to indent to the beginning of the indent level. Use spaces for all other alignment, including if you want to go a little further in than the indent level for some reason.

      Then, it all works perfectly and in 99.9999% of cases, someone can change the width of the tab character to whatever they like and it'll look right.

      Then silly people can use tab=8, weirdos can use tab=2 sick fucks can use tab=3 and the rest of us can view it as the gods decreed with tab=4. Feel free to permute that as per your preference except for the tab=3 clause.

      --
      SJW n. One who posts facts.
    4. Re:Spaces are for people who don't understand tabs by cfalcon · · Score: 2

      > It pains me that "tabs for indentation, spaces for alignment" seems to be such a minority.

      (tab)(tab)(tab)(space)(space)(space)Word1
      (tab)(tab)(tab)(tab)Word2

      Which one should be further to the right?

      Tabs + spaces is not even salvageable with a goddamned sed. You need to line by line that horseshit. At least I can fix a tab-damaged file with a script and a git command, your advice will cost serious time.

  7. Theory vs. Practice by rockmuelle · · Score: 5, Insightful

    In theory, tabs are the right solution. In practice, spaces are the right solution.

    -Chris

    1. Re:Theory vs. Practice by TFlan91 · · Score: 4, Interesting

      I disagree.

      I disagree with the whole debate entirely...

      Tabs for indentation, spaces for alignment AFTER indentation... Tabs so that people can choose whatever width they want, but after that width (meant for indentation of blocks) use spaces to align whatever you want...

      It really isn't that hard and it pleases everyone.

    2. Re:Theory vs. Practice by Kjella · · Score: 2

      In theory, tabs are the right solution. In practice, spaces are the right solution.

      I disagree. I disagree with the whole debate entirely... Tabs for indentation, spaces for alignment AFTER indentation... Tabs so that people can choose whatever width they want, but after that width (meant for indentation of blocks) use spaces to align whatever you want... It really isn't that hard and it pleases everyone.

      1. Congratulations, you win the "theoretically correctest" award
      2. I'd be happy if functions and variables had sane names
      3. Except those who have to write it, they're not pleased

      --
      Live today, because you never know what tomorrow brings
  8. In a world, where tabs were the right size... by Maltheus · · Score: 2

    I think there'd be less of a debate if tabs were 4 chars in width, out of the box. Not sure they'd even bother with a tabstop setting had that been the case. Granted, you're always gonna have your freaks, like this one guy I worked for who insisted on 3 spaces for indentation, but they would have gotten nowhere had the default tabstop been reasonable from the start.

    That being said, spaces for work code, tabs for personal code.

  9. Re:Systematic Suppression by Anonymous Coward · · Score: 2, Funny

    All this proves is that we Tabbers are being universally and systematically supressed by the Spacers (except in the Go community).

    That's because when the Spacers kick the Tabbers out of the building they shout "Just go!", and the Tabbers think that's a language recommendation.

  10. Re:Both. by WallyL · · Score: 5, Insightful

    Ew. That's an unusual combination of tabs and spaces.
     
    ...and also because of Emacs.

  11. Re: Deterministic behavior by Anonymous Coward · · Score: 2, Insightful

    If you use proportional fonts for programming, you deserve every bad thing that happens to you.

  12. Re:Both. by quintus_horatius · · Score: 2

    meaning 10 spaces would be indented using 1 tab and 2 spaces.

    That is truly the worst of both worlds. If you're going to use tabs, then tabs should be used for indenting (i.e. the block-level of the code) and spaces for formatting after the appropriate indent has been achieved, and the two should not mix.

    Doing it your way will improperly display in any other editor or viewer, including Emacs, that has a different-width tab -- which is pretty much all of them, since the 4-space tab-width is so popular.

  13. Spaces are the Betamax of coding. by RightSaidFred99 · · Score: 2

    And by this, I mean spaces are inferior, just like Betamax actually was.

    Tabs are, of course, more logical because it lets the person viewing/editing the code decide how it looks. You can set your tab width to 2 chars for super tight code, 3 for a bit more obvious indentation, or a more standard look with 4. You can even go nuts and go with 8 spaces.

    A tab semantically means "indent this one level". Two tabs = 2 indentations, etc... What the _fuck_ does 8 spaces mean? Is that one indentation or two? Oh, that's right, you have to look at the rest of the existing code to figure it out.

    It's god damn ridiculous and to hell with the Spacers.

    1. Re:Spaces are the Betamax of coding. by Yunzil · · Score: 2

      As a Spacer, you Tabbers will be the first against the wall when the revolution comes.

    2. Re:Spaces are the Betamax of coding. by swilver · · Score: 2

      Except those annoying tabbers don't know how to tab properly. They use them everywhere, in comments, at the end of a line, etc. See how well that lines up when you change the tab size...

      Only tab for indentation at the start of a line. Never mix tabs/spaces for identation. Then it might work.

      Since most people don't have the time to care about this, teams decide to use spaces so it looks uniform everywhere. It's much easier to explain how to space properly than how to tab properly.

  14. Re:Skewed by Qzukk · · Score: 2

    The argument was never about what button you push on your keyboard, it has always been about how fucked up your shit gets when someone else opens it in a different editor.

    --
    If I have been able to see further than others, it is because I bought a pair of binoculars.
  15. one thing the tabs and spaces folks agree on by dlang_rocks · · Score: 5, Funny
  16. People use spaces four times as often as tabs! by Richard+Kirk · · Score: 4, Funny

    (snigger)

  17. Well, that proves it! by zieroh · · Score: 2

    This was an analysis of files on github, yes? And by definition, those files are managed by git, yes?

    And thus, the files were created by all the young punks that rushed to git, because reasons, yes?

    In light of those conditions, yeah. I can see why there's a prevalence of spaces. The analysis only considers the work output of (mostly) young idiots.I'll bet there's a prevalence on github of non-plumb braces, too.

    --
    People who say "sheeple" have about as much sophistication as an AOL user, and in fact are probably actually AOL users.
  18. Re:You have to use tabs in the Linux Kernel by serviscope_minor · · Score: 3, Insightful

    You have to use tabs, sure, but how on earth are they going to know what width you set them to?

    --
    SJW n. One who posts facts.
  19. Re:C programmers clearly some kind of deviants by serviscope_minor · · Score: 2

    The type system is absolutly fine.

    It's tiny and incredibly primitive.

    If you think you need generics, you're doing it wrong.

    I don't think I need generics, I know they make my life easier and so I want them. I've programmed for years both with and without them.

    The funny thing of course is that go has certain generic structures, such as arrays, and maps clearly indicating that generic structures are worthwhile. It's jsut you can't define your own so if your problem domain doesn't map well on to the built in generics, it's a much worse language than if your problem does.

    --
    SJW n. One who posts facts.
  20. Re:Deterministic behavior by mattventura · · Score: 3, Insightful

    But that's what I like about tabs. They can be set to display as however many columns each individual wants, rather than requiring everyone to agree on the same number. 4? 3? 8? Pi?

  21. Bad Regex = Invalid Results by Anonymous Coward · · Score: 3, Insightful

    The regex used for determine tab vs. space is r'[ \t]', which matches the first space or tab in a line, not whether or not the first character in a line is a space or tab. Thus, for example, a using statement in C# (using System;) would count towards the spaces total where it shouldn't count towards either (unless preceded by spaces or tabs for some reason).

    Fix the regex (r'^[ \t]') and rerun it, i doubt it will allow tabs to win (tabs rule spaces drool), but it would give more accurate results for the charts.

  22. A couple of things... by erapert · · Score: 2

    1. .json files shouldn't be counted because they're frequently generated by tools rather than by humans (or even human tools...)

    2. Making an argumentum ad populum (i.e. an argument for or against spaces) is really just embarrassing yourself.

    3. Arguing that everyone should use spaces for indentation just because that's how the rest of the project is formatted is nothing more than an appeal to tradition-- furthermore we have tools these days which can automatically transform the whole project to use tabs so it's not like it would amount to re-writing every single file by hand to make the change.

    4. About the flame war... Here's a blog post that sums it up nicely. Spaces for indentation are objectively inferior, provide no improvement over tabs, and are more difficult to work with. If your reason for using them is just to force everyone else to do things (i.e. read and write code) your way then screw you: you're literally one of the reasons the world sucks.

  23. fibonacci indent by OrangeTide · · Score: 2

    on many of the old video terminals you could set arbitrary points for the tab stops. tab would jump your cursor to the next tab column on the current line.
    There is usually a command to set a tab at the current column, clear at tab at the current column and to clear all tabs. (VT100 and maybe VT52, probably no tab support in something ancient like ADM-3A)

    so you could setup 2 space for the first tab, 4 spaces for the next four, 8 spaces for the remaining.
    a the most elegant tab stop setup would be: 1, 1, 2, 3, 5, 8, 13, 21, 34, ...

    --
    “Common sense is not so common.” — Voltaire