Page 4 of 6

Re: Tabs vs Spaces

Posted: Fri Jun 12, 2009 5:01 pm UTC
by Agent_Irons
Four seems like a decent tab size. Two is a bit small, eight is definitely too big, and 3 isnt a power of two.

However, I have yet to find someone unhappy with tabbing to the correct level of indentation, then using spaces to set alignment (I actually hate alignment. I also hate "spaces between operators and variables" though. I'm a rebel)

Re: Tabs vs Spaces

Posted: Tue Jun 16, 2009 5:23 pm UTC
by lulzfish
I always have pointers as "ClassName * instanceName" because I love spacing things out.
but I stand by my original post, tabs are the only choice for indentation.

Re: Tabs vs Spaces

Posted: Mon Jun 22, 2009 10:14 pm UTC
by Phaedrus

Re: Tabs vs Spaces

Posted: Tue Jul 21, 2009 1:10 pm UTC
by lurkersanonymous
Surprised no-one has linked this yet.....

Image

I have ViM set to convert entries from the <Tab> key into 4 spaces for Python and Java. For WRAMP Assembly it is 8 spaces, but that is because the compiler gets upset if that is not the case.

Re: Tabs vs Spaces

Posted: Tue Jul 21, 2009 5:56 pm UTC
by ash.gti
I have started following the Google C++ style for C and C++ and their ObjC styles for ObjC.

http://google-styleguide.googlecode.com ... pguide.xml
and
http://google-styleguide.googlecode.com ... cguide.xml

Which is honestly pretty close to how I was doing things before, now I just stick to things like roughly 80 characters a line, and I shortened my naming schema a bit.

Re: Tabs vs Spaces

Posted: Tue Jul 21, 2009 8:25 pm UTC
by qbg
I believe Factor forbids tabs in source files, so there is no competition there.

Re: Tabs vs Spaces

Posted: Wed Jul 22, 2009 1:31 pm UTC
by Phaedrus
lurkersanonymous wrote:Surprised no-one has linked this yet.....

There is a case to be made for mixing tabs and spaces, though: use tabs for expressing the indentation level and spaces for lining things up. Or rather, set up your editor to format the whitespace in this way.

Code: Select all

int f(int x,
......int y) {
--->return g(x,
--->.........y);
}

That way, everyone can view the code with the amount of indentation they prefer simply by changing the tab size.

Re: Tabs vs Spaces

Posted: Wed Jul 22, 2009 1:51 pm UTC
by hotaru
Phaedrus wrote:That way, everyone can view the code with the amount of indentation they prefer simply by changing the tab size.

except for those who prefer to eschew indentation in favor of alignment, like so:

Code: Select all

int f(int x, int y)
{ x = g(x);
  y = g(y);
  return h(x, y); }

Re: Tabs vs Spaces

Posted: Wed Jul 22, 2009 2:21 pm UTC
by Phaedrus

Code: Select all

int f(int x, int y)
{>x = g(x);
->y = g(y);
->return h(x, y); }

Re: Tabs vs Spaces

Posted: Wed Jul 22, 2009 8:55 pm UTC
by ash.gti
hotaru wrote:except for those who prefer to eschew indentation in favor of alignment, like so:

Code: Select all

int f(int x, int y)
{ x = g(x);
  y = g(y);
  return h(x, y); }


I really gotta say, that does not, in my opinion, improve the readability of the code at all, simply because the brackets are seemingly thrown into a syntax that doesn't make sense. I can understand the logic behind it, but it really does not improve the situation in C or C like languages at all.

Re: Tabs vs Spaces

Posted: Thu Jul 23, 2009 1:18 am UTC
by null1024
MHD wrote:1 press on the tab key = 4 spaces.

PERIOD!


End of discussion. 2 spaces is too small, 3 spaces is weird, 5 is too much, 8 is way too much, and hard tabs suck, especially because you'd thing they were 8 actual spaces in one editor, load it up in another, and they'd be 6 or 4 visible spaces wide, and some of the lines wouldn't match.

Re: Tabs vs Spaces

Posted: Thu Jul 23, 2009 2:59 am UTC
by qbg
Two spaces, maybe because I'm use to Lisp...

Re: Tabs vs Spaces

Posted: Thu Jul 23, 2009 3:17 am UTC
by phlip
null1024 wrote:Hard tabs suck, especially because you'd thing they were 8 actual spaces in one editor, load it up in another, and they'd be 6 or 4 visible spaces wide

Why is this a bad thing? If someone who prefers to indent by 6 characters loads your file, they'll see it in their preferred 6 characters. And when they edit it (using hard tabs too, as presumably this would be a company style guide or something) and you load it, all their new code is shown indented by 4 characters, how you like it.
null1024 wrote:and some of the lines wouldn't match.

Only if you do it wrong.

Re: Tabs vs Spaces

Posted: Thu Jul 23, 2009 12:03 pm UTC
by Phaedrus
Tabs can accommodate everyone!

Code: Select all

// Tab size: 8             // Tab size: 4         // Tab size: 2

int f(int x,               int f(int x,           int f(int x,
......int y) {             ......int y) {         ......int y) {
------->return g(x,        --->return g(x,        ->return g(x,
------->.........y);       --->.........y);       ->.........y);
}                          }                      }

int f(int x, int y)        int f(int x, int y)    int f(int x, int y)
{------>x = g(x);          {-->x = g(x);          {>x = g(x);
------->y = g(y);          --->y = g(y);          ->y = g(y);
------->return h(x, y); }  --->return h(x, y); }  ->return h(x, y); }

Re: Tabs vs Spaces

Posted: Fri Jul 24, 2009 4:15 pm UTC
by Rysto
Tabs for indentation, spaces for alignment sounds great in theory, but people inevitably screw it up and make a mess of the source. It doesn't help that most editors get this totally wrong.

Re: Tabs vs Spaces

Posted: Fri Jul 24, 2009 5:10 pm UTC
by Phaedrus
Let the editor take care of the tabs and spaces for you. Vim has the Smart Tabs plugin, Emacs has Smart Tabs code for several languages, IntelliJ IDEA has a "Smart Tabs" option, and GNU Indent can be persuaded with -i99 -ts99 -l999. Works as part of the auto-indentation.

Re: Tabs vs Spaces

Posted: Sat Jul 25, 2009 1:04 am UTC
by xulaus
I use tabs for others convenience, but have set my tab width to 1. Suddenly it doesn't matter which one I use, provided no-one else uses my code.

Re: Tabs vs Spaces

Posted: Mon Jul 27, 2009 1:11 am UTC
by kernelpanic
Tabs. But the awesome, auto-multiple of 4 tabbing that emacs has.

Re: Tabs vs Spaces

Posted: Tue Jul 28, 2009 8:00 am UTC
by OOPMan
Spaces. Any decent editor has an Expand Tabs option which exists for all those who are aware just how much Tabs fuck everything up.

Re: Tabs vs Spaces

Posted: Tue Jul 28, 2009 9:42 am UTC
by phlip
OOPMan wrote:how much Tabs fuck everything up.
Such as?

What exactly to tabs fuck up, that isn't an example of the person doing the tabbing Doin It Rong (by which I mean failing at using tabs for indenting and spaces for alignment)?

Re: Tabs vs Spaces

Posted: Tue Jul 28, 2009 11:00 am UTC
by Amnesiasoft
Gotta go with phlip here, the only way tabs-for-indent/spaces-for-alignment can mess things up is if you're doing it wrong.

Re: Tabs vs Spaces

Posted: Wed Jul 29, 2009 3:06 pm UTC
by OOPMan
Tab = Arbitrary symbol that can be translate into X spaces where X is a random number between 1 and infinity

Space = An arbitrary symbol that indicates exactly 1, you guessed it, space!

Now look that happens when I open that file written by MacGuyver over there with mixed Tabs and Spaces. Alignment failure. If I wanted to sort through MacGuyvers poorly indented text and I would been an Journalism/Creative Writing tutor and he'd be yet another uselss BA undergrad.

Either uses spaces or uses tabs. If you're going to use tabs, use expandtabs. If you're not, get the hell of my lawn. This is not a democracy. You do not get to choose how many spaces your damn tab equals. Tabs are for socialists and other people who think that other people should be allowed to make ANY choices at all about ANYTHING. In my country, you use a space to indicate a space and that's it!

Re: Tabs vs Spaces

Posted: Wed Jul 29, 2009 3:13 pm UTC
by Amnesiasoft
You seem to misunderstand what we mean by usings tabs for indenting and spaces for alignment.

Code: Select all

int foo(int ..bar,
........float baz) {
--->ArbitraryFunctionName(3.141,
--->......................0, 0, 0);
--->return 0;
}


Now what happens when I change my tab size to 2?

Code: Select all

int foo(int ..bar,
........float baz) {
->ArbitraryFunctionName(3.141,
->......................0, 0, 0);
->return 0;
}


How about 8?

Code: Select all

int foo(int ..bar,
........float baz) {
------->ArbitraryFunctionName(3.141,
------->......................0, 0, 0);
------->return 0;
}


When you only use tabs to indent and only use spaces for alignment, it will work regardless of your tab size. Unless maybe you have word wrapping on...but if you have word wrap on, you're clearly doin' it wrong.

Re: Tabs vs Spaces

Posted: Wed Jul 29, 2009 3:16 pm UTC
by OOPMan
This isn't about tabs and spaces!

This is about choice!

Tabs = Choose your own Spacing!
Spaces = Use the Spacing I give you!

Any sane individual will go with the latter option because the former involves relying on other people, entities which can generally be shown to most likely to do the WRONG thing.

;-)

Re: Tabs vs Spaces

Posted: Wed Jul 29, 2009 5:15 pm UTC
by Phaedrus
OOPMan wrote:Any sane individual will go with the latter option because the former involves relying on other people, entities which can generally be shown to most likely to do the WRONG thing.

People make mistakes whether tabs or spaces are used; that's why auto-indentation was invented. (How could you else trust people to indent nested code consistently?)

The problem with spaces is there's no general agreement on how many to use, so the value used by the auto-indentation must be changed from project to project. Tedious. With tabs, the setting is always to emit one tab per indentation level, whether a tab is displayed as two columns or four.

Tabs are used consistently, but displayed differently; spaces are displayed consistently, but used differently.

And again: tabs for indentation, spaces for alignment. It is the auto-indentation's job to distinguish between the two, so you don't have to, just like you don't reformat huge sections of code by hammering the space bar.

Re: Tabs vs Spaces

Posted: Wed Jul 29, 2009 7:20 pm UTC
by lulzfish
Tabs have the following clear advantages:

1 keypress to adjust indentation, not 4
75% less file space (for a test sample consisting of 100% tabs equivalent to 4 spaces each)
If you use spaces, you hate America. Not just the US, you hate all of America. Even Canada and Mexico and Brazil.

Tabs use ONE character to represent ONE logical entity: An indentation.
Spaces use 4 characters and require the use of adjustment macros just to change the indent size.
It's like using a package manager... automating the problem instead of fixing it.

Re: Tabs vs Spaces

Posted: Wed Feb 03, 2010 11:04 pm UTC
by hackers238
Always spaces. Set VIM to expand tab to spaces.

Also map the tab key to word completion (if you're typing a word) Add the following to your .vimrc:

Code: Select all

function! Tab_Or_Complete()
  if col('.')>1 && strpart( getline('.'), col('.')-2, 3 ) =~ '^\w'
    return "\<C-N>"
  else
    return "\<Tab>"
  endif
endfunction
:inoremap <Tab> <C-R>=Tab_Or_Complete()<CR>


Taken from here: http://vim.wikia.com/wiki/Autocomplete_ ... ping_words

Re: Tabs vs Spaces

Posted: Thu Feb 04, 2010 2:51 am UTC
by achan1058
Spaces, since I don't want my code to be indented 8 space because I loaded it into notepad, or at places where I can't change the tab indentation.

Re: Tabs vs Spaces

Posted: Thu Feb 04, 2010 4:26 am UTC
by lulzfish
achan1058 wrote:Spaces, since I don't want my code to be indented 8 space because I loaded it into notepad, or at places where I can't change the tab indentation.

http://portableapps.com/apps/developmen ... p_portable

Tis nobler in the mind to take arms against a sea of failure, and, by opposing, end it.

Re: Tabs vs Spaces

Posted: Thu Feb 04, 2010 4:32 am UTC
by achan1058
Except that you might be using a Thin Client that does not have workable USB, not does it allow you to run random programs. (Though I personally try to stay away from doing anything more than e-mail with those things.)

Re: Tabs vs Spaces

Posted: Thu Feb 04, 2010 6:22 am UTC
by Meteorswarm
achan1058 wrote:Except that you might be using a Thin Client that does not have workable USB, not does it allow you to run random programs. (Though I personally try to stay away from doing anything more than e-mail with those things.)


Have internet, will vi.

Both

Posted: Mon Feb 08, 2010 5:13 pm UTC
by flying sheep
tabs for indentation, spaces for alignment, (like emacs’ smrt tabs linked to above) so would be one of those who get beaten up:
Image
but imho indentation is mostly bad coding style:
for huge constructors use variables (like kaboutdata. in my example, they indented, but this is not necessary since the arguments are used in the order the variables are assigned)
and if you want to create big string lists use text files or databases, don’t mix data with code!

Re: Tabs vs Spaces

Posted: Tue Feb 09, 2010 10:38 am UTC
by rar222
Here are the basic rules I follow at work :

Indenting C/C++/Java : 4 spaces
Indenting HTML/XML etc : 2 spaces (otherwise it's too verbose)

I've also worked on a 1M+ line, 20+ year old software package that is a combination of both C and C++. In it there are mixes of all coding styles, brace styles and indenting styles from an uncountable hoard of programmers using vi/vim/emacs/<inset editor or ide here>.

I've got to say the only way to ensure a measurable amount of readability is to banish all tab characters. At least with spaces it's always consistent. The number of files I found with mixed space/tab indenting was huge, and my general fix was to reindent entire source files using spaces only. Problem solved.

Re: Tabs vs Spaces

Posted: Tue Feb 09, 2010 7:51 pm UTC
by flying sheep
swich tab and space and your last paragraph would read:
I've got to say the only way to ensure a measurable amount of readability is to banish all space characters. At least with tabs it's always consistent. The number of files I found with mixed tab/space indenting was huge, and my general fix was to reindent entire source files using tabs only. Problem solved.
and still be wrong, since you can retab everything just like you can respace everything.

python is a little bit more difficult (in both directions), but possible, too. your choice is a matter of personal taste.

Re: Tabs vs Spaces

Posted: Tue Feb 09, 2010 7:55 pm UTC
by flying sheep
but still tabs are better :P
lulzfish wrote:Tabs use ONE character to represent ONE logical entity: A [single level of] indentation.
Spaces use [a variable number of] characters and require the use of adjustment macros just to change the indent size.
It's like using a package manager... automating the problem instead of fixing it.

Re: Tabs vs Spaces

Posted: Wed Feb 10, 2010 1:59 am UTC
by rm2010
Tabs. Have your editor decide how wide they should be. The only problem are people who refuse to spend the time configuring their editor.

Re: Tabs vs Spaces

Posted: Tue Jul 27, 2010 8:11 pm UTC
by Pesto
I'm coming in on the side of tabs. The current code base I work on is standardized to use four spaces, and our editors are set to expand tabs to spaces. I hate when I hit the tab key one too many times and I have to hit the backspace key four times to undo it.

Re: Tabs vs Spaces

Posted: Wed Jul 28, 2010 6:33 pm UTC
by Thesh
People who use spaces for indenting should be thrown into a burlap sack, beaten with sticks, hung in the office parking lot, and set on fire for all to see.

Spaces for indenting make keyboard navigation annoying.

Re: Tabs vs Spaces

Posted: Mon Aug 09, 2010 6:50 pm UTC
by enk
Pesto wrote:I hate when I hit the tab key one too many times and I have to hit the backspace key four times to undo it.


Hm, tried shift+tab?

I like to think of indentation as indentation, whether it's tabs or spaces. Use indent and dedent operations in your editor. Then you don't even have to think about tabs vs. spaces. Many editors use tab and shift+tab (typically, you'll need to select some text on the line(s) to make the tab key indent rather than insert a tab). For vim it is >> and << for the current line (and . to repeat) or V, then j/k to select some lines, then just > and < (again, . to repeat). Using = (or == for a single line) will indent correctly according to brackets. All good editors will do this for you. Except ofc in Python :P

Re: Tabs vs Spaces

Posted: Sun Oct 17, 2010 4:49 pm UTC
by bytbox
Tabs.

Why does everyone claim 8 is too much? Assuming the average length of a line is 40 characters (an overestimate, IME), and you want to avoid going over 80 characters (although for some lines, it might happen), that gives you 40 characters of indentation. 5 tabs. If you're nesting any deeper than that, you're screwed anyway. Whereas people who use 4 spaces think it's ok to do 10 levels of indentation, and people who use 2 (which appears to be the emacs default for some languages) think it's ok to do 20 levels...