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.
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!
All this proves is that we Tabbers are being universally and systematically supressed by the Spacers (except in the Go community).
... except for the times I use spaces.
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
The article conveniently ignores Python, a 100% tabbed language.
Paid Q&A/Research
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
And go programmers appear not to have space bars.
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"
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 outside of that).
When I write code (not my primary job but often enough) I use tabs much more than spaces. Most coders I know do the same thing.
-The wise argue that there are few absolutes, the fool argues that there are no probabilities.
C is more tabby and C++ is more spacy. Different IDEs I presume.
Slashdot, fix the reply notifications... You won't get away with it...
In theory, tabs are the right solution. In practice, spaces are the right solution.
-Chris
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 the two, but poor quality editors confused them, and so you ended up with tabs being re-defined as 4 characters, or even sillier things.
Given today's disk capacities, there is really no point in bothering with characters in your source files to achieve indents. Be specific, and have however many spaces you want. A decent text editor will let you configure the Tab key to give you whatever indent you want, but for goodness sake configure it to do it by way of spaces.
Back before the sizes of tabs got confused, I've used editors which would do the following:
First press of Tab - insert 4 spaces.
Second press - remove the 4 spaces and insert a hard TAB
Third press - add 4 spaces.
etc. It was all very clever, but unnecessary now.
Only because I use Python.
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)))
It must have been something you assimilated. . . .
Even when the user requests tabs, when the number of visible spaces is less than, say, 8 spaces, some IDEs save that indent with spaces, then convert as tabs if necessary when loading the file. This because most users set the tabs at 3 or 4 spaces. This way the user has its tabs when working in the IDE, and may still 'cat' the file that visually looks the same. The method used to consider a file 'tab' or 'space' based on the number of indents in either category is therefore (probably) inaccurate.
Slashdot, fix the reply notifications... You won't get away with it...
And neither are spaces (with proportional fonts)
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.
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.)
"Stratigraphically the origin of agriculture and thermonuclear destruction will appear essentially simultaneous" -- Lee
If you use proportional fonts for programming, you deserve every bad thing that happens to you.
I write shell and will copy code from my scripts to paste & run. Leading spaces are no problem. Tabs will invoke bash completion. No tabs! No capes! Remember Thunderhead? Sucked into a vortex!
And neither are spaces (with proportional fonts)
But editing source code using a proportional font is a way to drive yourself insane.
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.
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 different ways. especially if they are 'smart' editors and are going to take those tabs to mean something other than 'get out of my sight and go sit with your friends.'
but column selecting and backspacing spaces gets to be just as tedious. hell, moreso. it's 3-8 times as many keypresses. (3 for me, _thanks_!!!)
and most editors don't seem to get it goldilocks-just-right when it comes to assuming what i want when i'm starting a new line or removing an indentation. most of them either try too hard or force me into a weird hybrid of styles. i still haven't found an editor for windows that i can force to behave according to the style i came up with years ago and still prefer to use today, and i have tried some pretty configurable editors.
what i would really like is a standard that just says 'the indentation of this line is this many space', just have an integer and delimiter and hide them from view. i want the option to backspace all of it away without the behaviour being both tied to (parsing) and part of (outputting) the space and tab characters. especially if i decide to use a tab or several space in an unorthodox comment space.
i think it would be a lot easier for most editors to handle during their 'smart' indenting behaviour, as well. and there is already a notable standard for this in the old ansi terminal code definition. i'm always up for revitalizing the use and even advancement of that old shit.
"Stratigraphically the origin of agriculture and thermonuclear destruction will appear essentially simultaneous" -- Lee
Folks: You have no choice. In the Linux kernel, you have to use tabs and the tabs have to be set to eight spaces.
Most Respectfully Yours Mark Allyn Bellingham, Washington
It is time to turn around and walk the other way, unless you are entertained by stupid arguments.
Mac vs PC. Run the other way. I can get around in all of them. I swear less at Macs. I praise Microsoft for guaranteeing that I will continue to be employable till I die.
iPhone vs Android: Run the other way. I can get around in both. I swear at both of them equally for being moronic in different places.
Spaces vs Tabs: WTF? I don't worry about it... Sublime, textmate, etc do what they do. The only time I start crying is when Excel decides it cannot figure out quoted comma delimited content on text to column. (which I finally learned to paste, text to column, undo, undo, paste again and everything is fixed)...
Curly brace underneath function or to the right of the params parens? You can get me started on this in a meeting, but I will follow whatever the practice guidelines say for the company. I like to see the curly braces line up though.
Butter vs Margarine? Salted vs Unsalted? I prefer Butter. I prefer Unsalted.
God: "I don't leave footprints!"
https://www.emacswiki.org/emac...
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, which makes mechanical transformations of code much simpler. The amount of time wasted on formatting, both for writing and reading code is absurd.
I'll even suggest that a free-form text editor is an annoyingly primitive tool for programming. Given a suitable language and a canonical representation of the code, a contextually aware coding environment with full knowledge of the syntax could allow a significantly better development experience.
I know it's not popular, so it would never make the list. But disappointed nonetheless that Whitespace didn't get scrutinised. That data would have meant something!
One billion files?! That's why adults use statistics. Relatively small random sample would have given the same result.
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 worse as using spaces in web code is *mixing* spaces and tabs and indent depth.
That should be punishable with jailtime or something.
We suffer more in our imagination than in reality. - Seneca
(snigger)
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.
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?
pea-can vs. p-khan
potato vs. potatoe
space vs. tab
vim vs emacs
Spoiler alert: vim wins, like all the time.
Don't allow yourself to dream away time. Be productive. -- Some fortune cookie
From the link:
The solution - move tabstops to fit the text between them and align them with matching tabstops on adjacent lines
http://nickgravgaard.com/elast...
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.
But it depends what you're doing - you're writing code, you're viewing code in the editor of your choice. You might be printing code from the editor of your choice. If your code editor can't vary tab display/print widths, then it's your choice to not use one of the billions of modern editors or IDEs that can.
Stupid sexy Flanders.
Quick show of hands!
How many people use the tab key and how many use the space bar?
Wait I use both, except I don't use the space bar to line up my code.
God: "I don't leave footprints!"
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.
until you try moving to a different editor and now all the alignment is messed up.
It turns out codingstyle-related debates become mostly inexistent when people don't have to manually enforce the stylistic rules themselves.
So just hook uncrustify or astyle at the beginning of your build process, and commit the configuration file. Problem solved.
It would be pretty easy to represent a parse tree as XML.
I'm not sure how old greybeard C programmers would feel about keeping source code in XML.
(actually I'm very sure, and I was tempted to post AC to avoid the pitchforks)
“Common sense is not so common.” — Voltaire
They're the character which exist for indentation.
Obviously we must place the starting brackets in the function definition as you have done, because:
1) if the bracket starts on the following line then it might accidentally line up in the same column with the closing bracket and make the code block too easy to visually identify.
and
2) there is a world-wide shortage of carriage returns and they must be carefully rationed.
Support Right To Repair Legislation.
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
If spaces can win then anything is possible. Trump presidency here we come.
I have two things to say about code style nazis:
1) If you totaled up all the money spent on trying to make code pristine in code reviews, you probably could have solved world hunger
2) You can have all the pristine code you like, but if it doesn't work, it's absolutely worthless. It's a big, shiny you know what.
Summary: this discussion and my post consequently are a complete and utter waste of time that I can now never get back. :P
Obligatory XKCD: https://xkcd.com/974/
We'll make great pets
Most IDE's (and some better text editors) have options to convert from spaces to tabs, and from tabs to spaces. Choose your preference, select "reformat" and get on with the job of writing software.
The debate was interesting back when all we had were dumb text editors, but it's entirely pointless now.
Which is the entire point. I like my tabs wider than most people it seems. I find it helps me notice when something is getting too complex for a single unit.
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?
Only for indentation, not for alignment. If you care about writing readable code you'll use spaces.
I'm a minority race. Save your vitriol for white people.
Spacers are going to convert the tabs to spaces. Tabbers don't covert them back. -> eventually, it will all be spaces.
Most linux users don't know this, but the man pages were named after Chuck Norris. Chuck Norris fsck'ing hates noobs!
It would be pretty easy to represent a parse tree as XML. I'm not sure how old greybeard C programmers would feel about keeping source code in XML. (actually I'm very sure, and I was tempted to post AC to avoid the pitchforks)
It's been done. That still didn't solve the problem of indentation and alignment:
I'm a minority race. Save your vitriol for white people.
What kind of idiot would code without fixed width fonts? That's the stupidest thing I've ever heard in my life. Is that a real thing? Is someone actually that stupid?
Personally, I prefer spaces for indentation, and tabs for alignment.
If this is something that's a real problem for you, it's your fault. Even VIM can handle 'tabcount=4'. Assembly, x86 & AT&T, needs actual tabs in one's code. If your IDE out you can't figure that out and really find this to be an issue? Try Qbasic, Gambas, or actually evolve to real languages. Python is and always will be a teaching/learning language. I would hope coding gets better. But in my 20 years engineering what goes for 'code' is to script kitty to even be engineering. No python doesn't count, php barely, Perl?okay:sure, C/C++, Java, and more. - yes I ranted more than a bit. This is a huge pet peeve of mine. Because NO it makes no difference unless you're so dumb you shouldn't be writing code at all.
a rule is all you need for indentation and/or alignment once you have the language in a generalized form.
“Common sense is not so common.” — Voltaire
...use ASCII text files for source code?
If we used some smarter format, the IDEs could just display the formatting to individual taste. No more format wars.
Of course, all current revision control systems would be obsolete, but they're kludges anyway, because text files.
Yeah. Best there should be a systemd module that stores the code for us.
> Because your shitty text editor should be able to handle cutting and pasting them.
Like all tabbers, you begin by dismissing every editor you don't personally like, and taking joy in hurting those who don't use your exact solution. How excellent. What a team player. It's fine that your code can only be edited properly in your own personal IDE.
What a joke.
> It would be pretty easy to represent a parse tree as XML.
Well, you definitely came up with something worse than tabs. Now the file just fucking starts as garbage for everyone. And everyone who doesn't use your exact IDE can get bent, I guess. And uh oh, there was a bug in the XSL, and now we have a goto fail bug.
I definitely admire your dedication to finding novel ways to insert bugs into C code. We have so many already, and the elders told us that all the ways had been discovered. And here you go proving them wrong!
a rule is all you need for indentation and/or alignment once you have the language in a generalized form.
Lisp s-expressions *are* the generalised form for all programming languages. XML, for example, is syntactically a limited and crippled but more verbose representation of s-expressions. All XML can be run through a regex that will spit out conforming s-expressions, but not all s-expressions can be regexed to XML.
I'm a minority race. Save your vitriol for white people.