4 ms·
Google Coder Analyzes a Billion Files to Find a Winner in Tabs vs. Spaces Debate
- Derpdiherp 10y agoC++ Developer - must admit I used to use spaces, then switched to tabs. This was for several reasons - firstly - makefiles will not be parsed correctly if you start using spaces rather than tabs, so it's a good habit to get into to use them elsewhere to save headaches. Secondly, almost every developer I've met will want to use a different amount of spaces for indentation. When using tabs they can set whatever they want using the text editor or IDE of their choice. This is my line of thinking anyway.
- gcb0 10y agojs developer will tell you otherwise: "tabs will break npm" the whole debate is futile. but as least you're on the right side :) go tabs!
- AstralStorm 10y agoThis is 2016 calling, we have much better build tools than Gnu Make. Let's start with pretty popular Cmake, which has no problems with whitespace.
- Nursie 10y ago>> Should you use the tab button or five spaces when you're indenting source code? Five? What sort of freak uses five? And you should use the tab button, with your editor set up to insert four spaces instead of tab characters. This way display is consistent across editors, platforms etc etc I must say I'm surprised at the result for 'C' on there, as I've never worked with a C programmer that used tabs.
- Aardwolf 10y agoAgreed, except s/four/two/ :) And except for those few language where strangely tabs are required, like makefiles :(
- Nursie 10y agoLOL. Always found two a little too dense personally. And yeah, meaningful tab characters in Makefiles are a real sod...
- harperlee 10y agoI guess that would depend on the density of the language - I prefer 2 for clojure / common lisp and 4 for C and python. At the end, we're trying to optimize for readability, and the horizontal indentation needs to be more or less in harmony with how tight the code is vertically... for example, see this completely random and subjective selection from two of my projects: void consumeInput(gap * sudoku, inputQueue * q){ unsigned short int x, y, i, data; input * ptr = q->head; q->head = ptr->next; x = ptr->x; y = ptr->y; data = ptr->data; free(ptr); if(!q->head) q->tail=NULL; if(DEBUG) fprintf(stdout, "%d %d %d:\n", x, y, data); x--;y--; (defn username-from-req [ring-request] (when-let [identity (:cemerick.friend/identity (:session ring-request))] (let [[[:authentications auths] [:current curr]] (vec identity)] (when (and auths curr) (str (:identity (auths curr))))))) (My) C functions tend to be longer but with shorter lines, whereas with clojure, I end up writing denser functions with fewer lines with more meat, both in term of characters and semantics. Thus (again, for me), clojure looks better if lines are more "tight", and C needs more breathing space.
- dghf 10y agoOff topic, but could you explain the destructuring form you've used in your Clojure function? I've not seen destructuring with keywords in first position (in vectors, no less) before: is this something new for 1.9? I can't get it to work under 1.8. What does it offer over the standard associative destructuring form: (let [{auths :authentications, curr :current} identity] ...
- harperlee 10y agoWell it seems to work with 1.7. Try: (let [[[:a a] [:b b]] (vec {:a 1 :b 2})] (println a b)) But yeah, it's just an old and ugly hack from when I knew no better. It should look like your version.
- verroq 10y ago>I've never worked with a C programmer that used tabs. cough linux kernel cough
- Nursie 10y agoHuh, guess so, just looked at the style guidelines. I haven't done much with the kernel (nothing merged back upstream anyway), so I guess it never came up.
- ahoka 10y ago'Ellemtel' uses 3 spaces.
- Bino 10y agoAnd let's assume most programmers don't changes their editors auto-indent default. How does this affect the result?
- zappo2938 10y agoI just checked Webstorm which converts tabs to spaces so all my code is spaces but I only tabs. Go figure.
- lolc 10y agoThe only reason I accept why spaces should be used is that people are unable to configure their editors apparently.
- AstralStorm 10y agoTabs get munged by quite a few tools, including clipboard managers, webpage forms and more...
- speps 10y agoI wish more projects would start using this : http://editorconfig.org/ http://editorconfig.org/ I don't care whatever the original author of a project used, as long as my editor does the same automatically when I contribute.
- anotheryou 10y agoIt's strange, that the white space in languages without "meaningful white space" has any impact after all. Of course I like a blank line between blocks of more related functions, but I wonder why there is no standard for such things. Many text editors do the right step and auto-convert to your preferred spacing, but it's still strange there is no standard for it.
- dorianm 10y agoIt would be interesting to see if there is a trend on the spaces / tabs per language statistics, and I would also be interested by the numbers of spaces per language. e.g. I always use two spaces, but I mostly code in Ruby / JS / CoffeeScript. And that may influence my preference.