C++ 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.
>> 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.
I 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.
Off 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:
You're right, it works under 1.7. But not under 1.8: I get an "Unsupported binding form" exception.
A bit of digging suggests it was an unwanted side effect of allowing destructuring of name-spaced keywords in maps, introduced in 1.5:
> CLJ-1318 ("Support destructuring maps with namespaced keywords") introduced two potentially undesired behaviours:
> [snip]
> 2. Keywords were allowed in any binding key positions. Keywords are converted to symbols (retaining namespace) and treated according to the rules of symbols in the rest of the destructuring logic. From what I understand the idea was to allow keywords only in map destructuring, but again the change change was effected for any binding key.
We had people in the same team with the same differing opinions 15 years - we compromised on a coding standard of 3 spaces, and anything else looks wrong to me now.
It'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.
It 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.
21 comments
[ 4.9 ms ] story [ 52.5 ms ] threadThis 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.
the whole debate is futile. but as least you're on the right side :) go tabs!
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.
And except for those few language where strangely tabs are required, like makefiles :(
And yeah, meaningful tab characters in Makefiles are a real sod...
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:
(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.What does it offer over the standard associative destructuring form:
A bit of digging suggests it was an unwanted side effect of allowing destructuring of name-spaced keywords in maps, introduced in 1.5:
> CLJ-1318 ("Support destructuring maps with namespaced keywords") introduced two potentially undesired behaviours:
> [snip]
> 2. Keywords were allowed in any binding key positions. Keywords are converted to symbols (retaining namespace) and treated according to the rules of symbols in the rest of the destructuring logic. From what I understand the idea was to allow keywords only in map destructuring, but again the change change was effected for any binding key.
-- http://dev.clojure.org/jira/browse/CLJ-1778
1.8 removed keyword-first destructuring forms for vectors.
cough linux kernel cough
I haven't done much with the kernel (nothing merged back upstream anyway), so I guess it never came up.
I don't care whatever the original author of a project used, as long as my editor does the same automatically when I contribute.
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.
e.g. I always use two spaces, but I mostly code in Ruby / JS / CoffeeScript. And that may influence my preference.