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.
Tabs are not the same size in all rendering schema.
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
Tabs all the way
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.
... most people are idiots.
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.
The language defines and requires one, and only one, space/tab convention (hard tabs) and bracket hugging style. To settle any holy-wars 'go fmt' is built in which normalizes the source prior to building.
Golang uses tabs while I personally prefer spaces, but I don't care because they included a tool to make it irrelevant.
Only because I use Python.
When an advertisement like this can get through the editorial process of a self-proclaimed news website, it's hard not to think of the latest South Park season as a cautionary tale.
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...
Of course spaces win. Whoever uses tabs to separate words should be shot. Well, unless you're being paid by the line and have an 80 character limit. And even worse, not everything allows you to enter tabs. For an example, this comment input field can't handle them. Tabs are only supported by higher quality editors.
AAAAHHHHHH!!!! I typed all that with tabs instead of spaces and they were all converted to spaces! Down with tab percussion! Just say no to the corrupt and monolithic spaces ruling class! Whatever happened to equality?
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.
Your editor will compensate anyway and as an added bonus it helps to foil the maintenance programmer, especially if you mix tabs and spaces with statements and declarations.
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
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 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.
This is disappointing. Spaces are such a pain. If I import code that uses spaces, I am compelled to convert to tabs for consistency. I use 'vi' with ts=4. My language of choice is C. I always know the indentation is tabs, not spaces.
I'd use tabs exclusively, but I prefer 4 or 2 space indents, depending on the language and situation. Having edited code written by people who use tabs but set their tab stops to something different (e.g. 3), I definitely don't want to go that route. Not only is it not apparent from looking at it that the tab stops aren't at 8, but most software I use assumes 8-space tabs and provides no real way to change it (especially for just one file).
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
Macs suck, PC master race !!!!!
VI forever, you emacs users can lick my chuddy !
Java is way better than C#
if you are going to post flamebait like tabs vs spaces you might as well use traditional topics and get a better reaction.
AC
Of course you mix, tabs to indent, spaces to align! This hybrid is the best of both worlds.
C code (real code), uses tabs.
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.
Simple, don't use toy scripting languages with rely on whitespace scoping. Brackets, baby! Always brackets!
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.
would you rather use spaces or tabs?
Yes.
I realize some might say "no," but as for me, the answer is "yes."
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.
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.
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.
The question is not spaces or tabs
The question is spaces or tabs2 or tabs3 or tabs4 or tabs8 and probably some other preferences.
Given that there is no clear definition of what a tab is supposed to do, spaces are the only choice that actually works across a diverse set of developers.
Because your shitty text editor should be able to handle cutting and pasting them.
And if you weren't incompetent, you could adjust tab width in your text editor to be whatever fucktarded random number of spaces you think is "proper".
Code should be defined and stored as an AST. We should add formatting in whatever manner we prefer in the UI layer.
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.
According to the SO dev survey (2015) Tabs are preferred to spaces (45% vs 35%).
But wait, there's more....."Upon closer examination of the data, a trend emerges: Developers increasingly prefer spaces as they gain experience. Stack Overflow reputation correlates with a preference for spaces, too: users who have 10,000 rep or more prefer spaces to tabs at a ratio of 3 to 1."
Source: http://stackoverflow.com/research/developer-survey-2015
Or as I like to think of it, once you have been around long enough to collaborate with other people, you will want to use spaces. I think the TABs group is full of people who code with zero consideration for others. As for how many spaces is correct - that depends entirely on the style guide designated by your project/place of work/whatever.
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!
Most of the projects on github are CSS/HTML/javascript stuff, of course they're going to use spaces.
Really? A misused and inefficient serialization format, yes.
XML at least opens the door to metaprogramming, but not in its purely declarative form.
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.
Because the code viewer on GitHub only displays tabs as 8 spaces, making everyone's code look wrong. You are either forced to adopt spaces over tabs or you have to run a script to convert all your tabs to spaces every time you push. If you don't, you'll have coders complaining non-stop.
set sw=4
set ts=8
...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.
Get over yourselves. The rest of humanity doesn't care.
The tab key and space bar were invented long before anyone gave a shit about your pathetic opinions.
Go tackle something more important and tougher to figure out, like what's for lunch.
No wonder why Slashdot's dying. The incessant navel gazing is agonizing for those of us with lives.
But it is fun to watch the implosion.
tab-tab-void functionName(
tab-tab-tab-int argumentName1,
tab-tab-tab-int argumentName2
tab-tab-) {
tab-tab-tab-..........
tab-tab-}
like betamax ... and tab is way better.
because many IDE even convert tabs to spaces and so many programmers don't care about indentation, I often come across with so many libraries have really horrible indentation. It is so gross to look at them.
I assume you are trolling, but if anyone misses it: this is the worst possible thing, because the tab length is not defined (and supposedly the user can choose anything). In practice, every code I've seen with tabs to indent also has spaces, such that if you don't know the magic decoder ring the dev used, you can't even use the file.
...when there is a universal standard that is 100% deployed for they are expanded. In words, the 12th of Never.
You have clearly never tried it, no matter how wide your tabs are things will always look correct.
int foo()
{
____if-(x == 1
____-&&-y == 2
____---)
____{
________foobar();
____}
}
Where _ is tab and - is space.
For the longest time, I still can't understand the reason behind using spaces over tab. All editor, even vim allows setting tab stop so everyone can format to how they like and still looking at the same "structure/format" underneath. Plus, with all that obsessions computer science course tries to stuff in student's head, one would thing tab would parses faster simply because we use less of them.... however how minute that is. So from both all fronts, space, speed and consistency, why would someone chooses spaces over tab.
believe it or not, the whole point of the tab key is what we use it for in coding. it moves your cursor to the next column.
using spaces was incorrect from the beginning.
you can use tabs to align text in a word processor. thats what its for, and you use tabs to do it. in text files and coding, tabs are just that.
any alignment issues between computers disagreeing on how long a tab is supposed to be well, thats a non-destructive configuration change in your IDE.