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.

20 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 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.

    3. 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!
    4. 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.

    5. 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!
    6. 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.

  2. 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
  3. 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 mrun4982 · · Score: 1, Insightful

      The problem with tabs is you pretty much have to format your code to use a certain tab width, else things won't always line up correctly when using a different sized width. I see this all the time with code that uses hard tabs. Thus, you might as well just use spaces. Unless you're a novice programmer, the coding style the author chose shouldn't affect your ability to read the code and modify it. Such things don't matter.

    2. 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.

    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. Theory vs. Practice by rockmuelle · · Score: 5, Insightful

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

    -Chris

  5. 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.

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

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

  7. 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
  8. 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.

  9. 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.
  10. 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?

  11. 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.