Tabs all the way, far, far less fiddely than spaces and everyone seems to use weird amounts with spaces....
Spaces
Tabs
Other
Tabs all the way, far, far less fiddely than spaces and everyone seems to use weird amounts with spaces....
Not when tabs are mixed with spaces. That's what we're talking about here.
Not that I'm really fond of the idea of code looking different in different editors, even with pure tabs. I'm sad to see tabs winning the poll right now.
And yet, you yourself said that you used to set them to four. Anyway, it's not always an option. (I've even seen at least one semi-popular editor that doesn't handle tabs properly at all, treating them as fixed numbers of spaces rather than moving to the next tab stop.)
Like I said, I used to do what you're doing. And I saw my formatting messed up enough times to realize it was a bad idea.
I don't think that any perfect solution exists unfortunately. Ideally everyone would just use tabs and then indents can be consistently as big or small as each of us likes.
But invariably with collaborative development, sooner or later someone will mix it. So I think the best "rule" is not to have a rule and just try to remain consistent with what's used in each file as it comes.
For my own purposes, I find code easier to read in a terminal using indentation with 2 spaces, so that's my default setting. I would expect that to be unpopular but, frankly, I've never found any alternative strategy to work out either better or worse for promoting consistency in reality...somebody will screw it up whatever you do.
And if they don't screw up the indentation, they'll do something else you think is ugly with the layout of conditional blocks, curly braces, line lengths, naming etc.
This is just one of the things we have to learn to live with, especially in the FOSS world Difficult when most programmers are naturally pedantic about this stuff (myself included).
I revoke my former statements and reluctantly see the error of my ways. Tabs FTW.
Yes. The problem is mixing. The problem is also that most people don't make a distinction between "indentation" and "alignment" of code.
Indentation refers to the amount of white space at the beginning of a line, while alignment refers to any other white space in the line to accommodate the text with a previous line, this is where most horrors happen.
Code:def f(): This is indented Four-spaces indentation (assume it's a tab) 1234 1234 1234 1234 1234 1234 1234 1234 1234 | | | | | | | | | | | | | | | | int boo = 56 ; /* There are two tabs */ int bas = 10 ; /* before the equals sign */ char[] var = "There is one tab before the equals sign" ; /* There is one tab after each equals sign */
Now change it to 6-spaces tab.
The indentation remains one tab, and it looks good. But the lines no longer align at the "=" character.Code:def f(): This is indented Six-spaces indentation (assume it's a tab) 123456 123456 123456 123456 123456 123456 123456 | | | | | | | | | | | | int boo = 56 ; /* Still two tabs */ int bas = 10 ; /* before the equals sign */ char[] var = "Still one tab, and it no longer aligns" ;
The alignment problem can be solved by always using spaces, without worrying about the amount of space used for indentation.
Again with six-spaces indentation, but using spaces for alignment:
Now with 9-spaces tabs.Code:def f(): This is indented Six-spaces indentation (assume it's a tab) 123456 123456 123456 123456 123456 123456 123456 | | | | | | | | | | | | int boo = 56 ; /* Five spaces before the sign */ int bas = 10 ; /* Five spaces before the sign */ char[] var = "Two spaces before the sign" /* The space after the sign could be a tab */ /* and it wouldn't affect the alignment */
I'm not sure if everybody gets my example.Code:def f(): This is indented Crazy 9-spaces indentation (assume it's a tab) 123456789 123456789 123456789 123456789 123456789 | | | | | | | | int boo = 56 ; /* Five spaces before the sign */ int bas = 10 ; /* Still aligns okay! */ char[] var = "Two spaces before the sign" /* The space after the sign is a tab */ /* and it doesn't affect the alignment */ /* because the reference is the "=" sign, */ /* which is correctly positioned with spaces */
In summary, understand the difference between indenting (at the beginning of a line), and aligning (everywhere else).
For indenting you can use tabs or spaces (be consistent!). For alignment you should only use spaces!
Ah yes, a very good point. This is probably the worst of all actually now that I think about it...people using a small tab size then use tabs to align something about 30 spaces in from the block "indent", so then when someone else opens it with 4 or 8 tab size sometimes the "aligned" code is so far off to the right you don't even see it
Even if we were to invent a set of fancy language parsers for all the editors that would redo the layout of the entire source file according to the parse-tree structure, you would still never be able to sort out this problem with tabbed alignment, except to remove any alignment at all!
I've never been a fan of "significant white space" in languages, but perhaps it is the only way to enforce a solution to this perpetual aggravation. And when I think about it like that I always conclude that messed up formatting is the lesser of the two evils and I curse myself for being such a pedant.
Happens in this same forum.
People use tabs to indent, and in their editor they (unknowingly) use 2 spaces expansion. Then they post code in this forum, which auto-expands to the classical 8 spaces.
So when people indent, in their own mind to 4 spaces, they actually use 2 tabs, or 16 spaces in this forum.
I've seen code like this here:
And then they are like, "lol, I don't no what's wrong with the spacing, sorry guyz, Windows sucks, lol"Code:for (i = 0 ; i < 99 ; ++i) { for (i = 0 ; i < 99 ; ++i) { if ( bla == 456) break ; } }
Bookmarks