400,000 GitHub Repositories, 1 Billion Files, 14TB of Code: Spaces or Tabs? (medium.com) 391
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.
Tabspaces? (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?
Re:Tabspaces? (Score:4, Insightful)
Any IDE can be configured to use spaces instead of when you indent.
Re: (Score:3)
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 fo
Re:Tabspaces? (Score:5, Interesting)
That's when it's time to run the code through a formatter an check it in again.
Re: (Score:2)
But does anybody seriously type all those spaces? You don't just set the Tab key to expand to spaces?
or most likely, the editor enforces formatting with whatever parameters you configure it with. That's emacs default setting in C for instance: pressing tab indents this line consistently with the one above.
Skewed (Score:2)
I happen to use Sublime today, Nedit previously, and both replace tab characters with spaces. I'd be willing to bet that other applications do the same thing. Obviously this skews the result because the author may use tab but tabs get converted without knowledge. Additionally, many places strip tabs from files on commits. Again, this skews the result. TFA didn't bother to mention a pre commit hook as that would change the fakerovercy (sorry, it may be funny for a TV show but pretty stupid to argue outs
Re: (Score:3)
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.
Re: (Score:2)
Re: (Score:3)
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.
Re: (Score:3)
" 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 c
Re:Tabspaces? (Score:4, 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.
Re: (Score:3)
Re:Tabspaces? (Score:4, 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.
Re: (Score:3)
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".
Re: (Score:2)
I don't care how you get the spaces in there, my editor does "smart spacing" for me, just as long as the saved file has spaces, not tabs.
One calorie Tab soda would be a good logo for tabs in files: 1 as in: only good for use in a single editor.
Re:Tabspaces? (Score:5, 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.
Re: (Score:3)
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.
Re: (Score:3)
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.
Re: (Score:2)
And these are source code files, yes?
Re: Tabspaces? (Score:5, 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.
Re: Tabspaces? (Score:5, Interesting)
Re: (Score:3)
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.
Re: (Score:3)
> 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.
Re: Tabspaces? (Score:5, 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.
Re: (Score:3)
I do. I find the rat-atat-rat-atat-rat-atat-rat-atat very therapeutic.
Re: (Score:3)
I always use tabs... (Score:4, Funny)
Re:I always use tabs... (Score:4, 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!
Re: (Score:2)
Tabs definitely.
Oh except for the GNU indentation style which is eye-clawingly hideous and is a mockery of both spaces and tabs.
what he said (Score:3)
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.
Re:what he said (Score:5, 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.
Re:what he said (Score:5, Informative)
https://en.wikipedia.org/wiki/... [wikipedia.org]
The article conveniently ignores Python (Score:3)
The article conveniently ignores Python, a 100% tabbed language.
Re:The article conveniently ignores Python (Score:4, Informative)
Wrong: https://www.python.org/dev/peps/pep-0008/#tabs-or-spaces
Re: (Score:3)
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.
Re: (Score:2)
Uh, it does include python, and PEP8 (which I, as a tabber, ignore) recommends using spaces, not tabs.
Re: (Score:2)
Definitely wrong. In our (medium sized) project all of our Python is space indented just like our C++ (consistency is key).
Of course... we all use editors that do the correct spacing by pressing the TAB key... but make no mistake _spaces_ are used. We actually enforce this with automated testing that runs on every pull request... any TAB characters will immediately cause your PR to fail tests...
Re: (Score:3)
Re: (Score:2)
Re: (Score:2)
Bzzzzzzt. Absolutely wrong. Google "PEP8". "Spaces are the preferred indentation method."
Re: (Score:2)
It also conveniently ignores (older) COBOL compilers that required spaces. You and your modern languages that get to use tabs...
Re: (Score:2)
Ah, a man after my own heart. I also use two spaces per indent level. Any more than two is kindergartenish. And yes, I realize that Guido hates me for this, but none of the stuff I write is ever seen by anybody except me, so I don't have to care about catering to those with bad taste. Whenever I used to work on Python code in a team, or made something somebody else might have to maintain later, I did adhere to the dreary prevailing bad taste.
Know what? I use
Re: (Score:2)
In my first proper programming job the standard was four spaces. Beurk! You run out of space more easily (some old systems limit you to 80 chars because punch cards) and I find it more jarring to read.
If you can't see a two space indent you should let your dog do the typing.
Doesn't matter who "wins" (Score:5, Insightful)
Popularity is a poor measure of quality. Otherwise McDonald's would be Michelin starred.
Re: (Score:2)
McDonald's would be Michelin starred.
Sorry, Michelin doesn't have negative stars
Spaces are for people who don't understand tabs (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"
Re:Spaces are for people who don't understand tabs (Score:5, 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.
Re:Spaces are for people who don't understand tabs (Score:5, 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.
Re: (Score:3)
> 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.
Re: (Score:2)
While I agree, there are two remaining issues: Cases where it still doesn't work, and tool support.
Tool support:
Do you know of an editor that replaces spaces with tabs only at the beginning of the line? That would make this problem moot. But every editor I've ever seen either puts tabs everywhere it can, or never puts them in. None seem to use them intelligently.
Special indent cases:
tab-tabvoid LongFunctionNameWithManyArgumentsWithLongNames(int argumentNumber1,
tab-tab-spaces-morespaces-std::hash_map>
Re: (Score:3, 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. W
Re: (Score:2)
The issue is that a lot of code has traditionally been 80 characters wide. That way anyone who looks at it in a standard size terminal will see the exact thing that the author saw when he wrote the code. Tabs are ambiguous in that, in a traditional 80 character wide display, you may have to guess what tab size the author used and changing that tab size may have unintended consequences.
Re: (Score:2)
If you're using NOTEPAD to edit code then that means you have to hit the space bar or backspace multiple times to indent code one level, and you risk highlighting or indenting only a fraction of an indent. So even in that case, tabs are STILL preferable!
Most developers aren't writing on very small screens anymore, and even if you are, you should know better than to write spaghetti code that goes more than a few levels deep (the "Inception Rule" of don't go more than four levels deep).
Interesting (Score:2)
Theory vs. Practice (Score:5, Insightful)
In theory, tabs are the right solution. In practice, spaces are the right solution.
-Chris
Re:Theory vs. Practice (Score:5, 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.
Re: (Score:3)
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
Re: (Score:2)
i always end the definition with the opening bracket so that there is absolutely no fucking way it goes missing. if it's not at the end of the line it hasn't been entered.
and then i usually close bracket in the exact same indentation as the code it's closing. this way when you're looking at a huge set of subroutines and starting to wonder where this or that set of lines was defined, you just find the closing bracket and follow the line up until your vision literally collides with the definition. ta-da, no m
Tabs are redundant these days (Score:2)
A long, long time ago, in a data centre far, far away...
Back in the day, a multi-user system might have had a single 4.8M hard disk, shared between the operating system and all its users. It made sense to use tabs instead of lots of spaces for indents, because each tab saved you 8 spaces - a pretty good compression ratio, and a worthwhile saving in disk usage.
Then came a period of chaos, where people started muddling up their desired indent with the size of a tab. Decent editors always let you separate th
Re: (Score:2)
s/bothering with characters/bothering with TAB characters/
Spaces... (Score:2)
Re: (Score:2)
I like to mix spaces and tabs when I use python because I like to use pedantic arsing around to troll people who claim Python is easy to read.
Re: (Score:2)
Makes even less sense to use spaces in Python or whitespace sensitive languages. Lots of frustration here from merging code bases from multiple people who decided to use a different # spaces to define a tab.
PEP 8 recommends spaces over tabs. Most IDEs will default to four spaces.
https://www.python.org/dev/peps/pep-0008/#tabs-or-spaces [python.org]
Both. (Score:2)
I use Emacs with a function bound to the Return Key that performs a and the re-indent function indents with tabs and spaces as appropriate -- meaning 10 spaces would be indented using 1 tab and 2 spaces.
(defun smart-newline ()
"(reindent-then-newline-and-indent) if in a mode listed in smart-newline-modes. Otherwise just (newline)."
(interactive)
(if (memq major-mode smart-newline-modes)
(reindent-then-newline-and-indent)
(newline)))
Re:Both. (Score:5, Insightful)
Ew. That's an unusual combination of tabs and spaces.
...and also because of Emacs.
Re: (Score:3)
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.
Re: (Score:2)
As long as the indenting method is consistent, there's generally no problem regardless of the displayed tab-width -- which people should just fucking leave at 8 spaces and don't use so many of them. (People that indent using only tabs should simply be killed.) In addition, I've been doing this since 1985 and neither I or my co-workers have *ever* had any problem with my code. To the contrary, code that has been edited (usually) in vi, indented using just tabs, but with a smaller tab-width is much m
Re: (Score:2)
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.
Also, to follow up, Emacs has language-specific mode styles and knows how to indent code properly. It just uses a mix of tabs and spaces to achieve that indenting. All of this is configurable, but I always use the default style settings. Many of the posts for this article mention editors doing smart indenting rather than people just using tabs/spaces willy-nilly.
Re: (Score:2)
Bzzzzzt. Combining tabs and spaces to make up a single indent level is BRAIN DEAD.
Actually no. Indenting w/just tabs is brain dead and indenting w/just spaces is counter-productive. Your low UID aside, I'll stack my 30 years of experience using Emacs like that against that any day.
Probably not accurate (Score:2)
In a world, where tabs were the right size... (Score:3)
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.
not where i thought this headline was going! (Score:2)
i was really expecting the argument to go,
"well, look at how much damn code is amassing through the collective efforts of all of us dumbasses.
"well considering how enormous the collective code base is getting,
"NOW how do you feel about using three times as much character data in your whitespace, HUH?!"
but instead it was just an enormous poll.
(i'm disappointed because it seemed like it would be an interesting debate.)
Shell scripts + copy&paste (Score:2)
Spaces are the Betamax of coding. (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, tha
Re: (Score:3)
As a Spacer, you Tabbers will be the first against the wall when the revolution comes.
Re: (Score:3)
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.
Re: (Score:2)
You also can't accidentally highlight half an indent when using tabs!
I prefer 3-space tabs myself, but this is pretty unheard of in the space-indent world.
ansi terminal code has some cool stuff (Score:2)
honestly i'd prefer if lines indented past 3 spaces were indented using some delimiter and integer.
i hate backspacing over numerous tabs and the more indented your code gets the more you're working with a falling apart mountain of tabs. sure, code manager, blah blah, what ever. the only reason we're talking about this is because enough of us are manually maintaining our code through traditional key bindings.
i prefer spaces only because i don't want to store tabs and deal with different editors treating tabs
You have to use tabs in the Linux Kernel (Score:2)
Re:You have to use tabs in the Linux Kernel (Score:4, Insightful)
You have to use tabs, sure, but how on earth are they going to know what width you set them to?
one thing the tabs and spaces folks agree on (Score:5, Funny)
https://www.emacswiki.org/emac... [emacswiki.org]
Re: (Score:2)
Correctimundo. The one standout brain-dead no-no.
Free-form code is too often a mess... (Score:2)
Expanded tabs are a waste of space. The reasonable solution is using tabs for leading indent, and space otherwise. Tabs provide proper semantic meaning for indent, allowing editors to respect user preference.
Fundamentally though, the question shouldn't even need to be considered. Code is necessarily structured and should have a canonical format, enforced by a tool like gofmt [golang.org], which makes mechanical transformations of code much simpler. The amount of time wasted on formatting, both for writing and readin
Re: (Score:2)
No. May I repeat myself? HELL NO.
Whitespace programming language (Score:2)
Statistics! (Score:2)
Tabs in web-development is an absolute must. (Score:2)
Tabs with PHP, HTML and other web programming languages. Not using them at least triples your filesize.
I remember replacing space with tabs and reducing outbound web documents from 90 kb to 30 kb with one simple search and replace.
Pretty much settling the argument at least in this field.
If I catch you using spaces in your web output, I will hurt you. Bad. And you will deserve it.
If you're using spaces in a compiled language - go right ahead. The compiler is a must and fixes it all.
Just as bad or maybe even
People use spaces four times as often as tabs! (Score:5, Funny)
Well, that proves it! (Score:3)
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.
Bad Regex = Invalid Results (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.
A couple of things... (Score:3)
2. Making an argumentum ad populum [wikipedia.org] (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 [wikipedia.org]-- 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. [verou.me] 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.
Re: (Score:2)
Re: (Score:2)
And go programmers appear not to have space bars. ... or a decent type system!
(or generics)
Re: (Score:3)
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 ge
Re: (Score:2)
And neither are spaces (with proportional fonts)
Re: Deterministic behavior (Score:2, Insightful)
If you use proportional fonts for programming, you deserve every bad thing that happens to you.
Re: (Score:2)
And neither are spaces (with proportional fonts)
But editing source code using a proportional font is a way to drive yourself insane.
Re:Deterministic behavior (Score:4, Insightful)
Re: (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.
fibonacci indent (Score:3)
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,