Tabs vs Spaces

Please compose all posts in Emacs.

Moderators: phlip, Prelates, Moderators General

Tabs vs Spaces

Postby _peterb » Fri Nov 23, 2007 8:16 pm UTC

IMHO tabs are more correct because the length of a tab is non defined.

Discuss.
_peterb
 
Posts: 5
Joined: Fri Nov 16, 2007 1:58 am UTC

Re: Tabs vs Spaces

Postby crazyjimbo » Fri Nov 23, 2007 8:29 pm UTC

It makes no odds really. Both have slight advantages over the other but I find that if I use tabs, it only takes 1 space to mess everything up, and cause what looks fine in your editor to look like garbled crap in someone else's. Also, to pass functions with arguments split over many lines, if you use tabs then you need to tab into your main block and then use spaces to line up your arguments. This isn't fun and generally gets done wrong. This is why I play safe and stick to spaces.

Above all though, BE F*CKING CONSISTENT!

EDIT:
IMHO tabs are more correct because the length of a tab is non defined.


That's a problem. How can something that can look different on everyone's computer be a good standard for consistent presentation?
User avatar
crazyjimbo
 
Posts: 887
Joined: Fri Apr 20, 2007 11:45 pm UTC
Location: Durham, England

Re: Tabs vs Spaces

Postby EvanED » Fri Nov 23, 2007 8:38 pm UTC

crazyjimbo wrote:That's a problem. How can something that can look different on everyone's computer be a good standard for consistent presentation?

For the same reason that it doesn't matter two hoots what font someone chooses for their editor.

Properly used, tabs are better because it allows people to choose the level of indent they want. However, they are somewhat hard to properly use, and it's hard to verify that a use is correct in a way that you can continually glance. (Coloring tabs or something like that doesn't count; too visually busy and ugly when you're trying to work on stuff.)
EvanED
 
Posts: 4035
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI

Re: Tabs vs Spaces

Postby Rysto » Fri Nov 23, 2007 8:39 pm UTC

Can we all agree that anybody who mixes tabs and spaces for indentation will spend an eternity burning in hell, though?
Rysto
 
Posts: 1433
Joined: Wed Mar 21, 2007 4:07 am UTC

Re: Tabs vs Spaces

Postby crazyjimbo » Fri Nov 23, 2007 8:50 pm UTC

EvanED wrote:
crazyjimbo wrote:That's a problem. How can something that can look different on everyone's computer be a good standard for consistent presentation?

For the same reason that it doesn't matter two hoots what font someone chooses for their editor.


My main gripe with their inconsistency is the point I mentioned above in that you need to switch between tabs and spaces to get consistent indenting of multiline methods. E.g.

Code: Select all
if something then
           my_method(argument_1,
                            argument_2);
<tabs>< spaces  >
end


The fact we need to do this stems from tabs not being consistent across environments and this is thus a problem. It relies far too much on us humans being good at indenting. Considering we can't even see what we are doing/have done, this is too much to ask.

On a related note, I hope everyone agrees that tabs should be 4 spaces :P

EDIT: Apparently code boxes don't preserve formatting any more. :( Sorry if that looks odd to you.
User avatar
crazyjimbo
 
Posts: 887
Joined: Fri Apr 20, 2007 11:45 pm UTC
Location: Durham, England

Re: Tabs vs Spaces

Postby EvanED » Fri Nov 23, 2007 9:02 pm UTC

crazyjimbo wrote:My main gripe with their inconsistency is the point I mentioned above in that you need to switch between tabs and spaces to get consistent indenting of multiline methods. E.g.

...

The fact we need to do this stems from tabs not being consistent across environments and this is thus a problem. It relies far too much on us humans being good at indenting. Considering we can't even see what we are doing/have done, this is too much to ask.

Yes, I agree. That's why it's hard.

On a related note, I hope everyone agrees that tabs should be 4 spaces :P

Unfortunately, not everyone does. There's some people in the one-true-style thread I think who think it should be a heretical 2 spaces. ;-)
EvanED
 
Posts: 4035
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI

Re: Tabs vs Spaces

Postby Sc4Freak » Fri Nov 23, 2007 11:07 pm UTC

I like a compromoise. My IDE (VS2005) inserts spaces when I press [tab], and also when backspacing whitespace it deletes spaces as if they were tabs. So I have all the convenience of tabs, and all the benefits of spaces.
User avatar
Sc4Freak
 
Posts: 673
Joined: Thu Jul 12, 2007 4:50 am UTC
Location: Redmond, Washington

Re: Tabs vs Spaces

Postby zenten » Sat Nov 24, 2007 4:15 am UTC

Sc4Freak wrote:I like a compromoise. My IDE (VS2005) inserts spaces when I press [tab], and also when backspacing whitespace it deletes spaces as if they were tabs. So I have all the convenience of tabs, and all the benefits of spaces.


Arg, no, that's the worst of both worlds. You get the fiddlyness of tabs on your login, and the lack of control on other environments.
zenten
 
Posts: 3796
Joined: Fri Jun 22, 2007 7:42 am UTC
Location: Ottawa, Canada

Re: Tabs vs Spaces

Postby Amnesiasoft » Sat Nov 24, 2007 10:21 pm UTC

Tabs for indent. Spaces for alignment. Is it really that difficult? My brain says it's easy, but the uneducated masses say it's difficult.
User avatar
Amnesiasoft
 
Posts: 2575
Joined: Tue May 15, 2007 4:28 am UTC
Location: Colorado

Re: Tabs vs Spaces

Postby Cheese » Sat Nov 24, 2007 10:52 pm UTC

I go with amnesiasoft. I find it so much easier to just mix the two - if someone else really, really wants to read my code, it's usually well commented. I'm generallyonly use one editor per project, so no layout problems when I want to change something.
hermaj wrote:No-one. Will. Be. Taking. Cheese's. Spot.
Spoiler:
LE4dGOLEM wrote:Cheese is utterly correct on all fronts.
SecondTalon wrote:That thing that Cheese just said. Do that.
Meaux_Pas wrote:I hereby disagree and declare Cheese to be brilliant.
Image
User avatar
Cheese
and spam. (Euggh)
 
Posts: 3908
Joined: Mon Jul 02, 2007 2:04 pm UTC
Location: ¿burning you?

Re: Tabs vs Spaces

Postby enk » Sun Nov 25, 2007 1:30 am UTC

Vim documentation recommends always letting vim show the tab as (up to) eight spaces as thats the standard others will use (set tabstop=8). Then it will look the same everywhere.

Then you can use shiftwidth and softtabstop settings to control the amount of "visible whitespace" the tab, indent, unindent and backspace key will insert/remove. Soft tabs are composed of hard tabs and spaces.

So if you do it like this, you can indent as many whitespaces as you like (e.g. 4) and the only difference is whether you save seven bytes each time you see eight spaces worth of white space.
phlip wrote:Ha HA! Recycled emacs jokes.
User avatar
enk
 
Posts: 754
Joined: Mon Sep 10, 2007 12:20 am UTC
Location: Aalborg, Denmark

Re: Tabs vs Spaces

Postby Marvin » Sun Nov 25, 2007 1:35 am UTC

tabs are faster...
42
--
If God intended us to program we would be born with serial I/O ports.
User avatar
Marvin
 
Posts: 153
Joined: Thu Nov 22, 2007 8:03 am UTC
Location: Croatia

Re: Tabs vs Spaces

Postby Anpheus » Sun Nov 25, 2007 1:45 am UTC

I find tabs or spaces fine, though I prefer to edit any release code to replace tabs with spaces so that it looks the same to everyone else (and honestly, if you're editing code with a box that doesn't have regex to do the reverse, what the fuck development environment are you running there?)

What I find insane is the eight spaces per tab, it's creates really awful spread-eagle code that rapidly becomes wider than my widescreen monitor. Combine eight spaces per tab with the 100-odd nonstandard characters that different projects will decide is the end of a line arbitrarily, and pretty soon you get unreadable code. Combine that with all a manner of personal preferences for different type and variable naming, and you get insanity.

Uniformity here, that's all I ask for. If everything just looks uniform I'll be happy. I don't care if it's tabs only (don't align shit if you do this though,) spaces, tabs and spaces, or whatever whitespace character you want, as long as I can change how it looks on my box. Most of the time a few regex find&replace ops will give me something I'll be ok using.
Spoiler:
Code: Select all
  /###\_________/###\
  |#################|
  \#################/
   |##┌         ┐##|
   |##  (¯`v´¯)  ##|
   |##  `\ ♥ /´  ##|
   |##   `\¸/´   ##|
   |##└         ┘##|
  /#################\
  |#################|
  \###/¯¯¯¯¯¯¯¯¯\###/
User avatar
Anpheus
I can't get any worse, can I?
 
Posts: 860
Joined: Fri Nov 16, 2007 10:38 pm UTC
Location: A privileged frame of reference.

Re: Tabs vs Spaces

Postby Rysto » Sun Nov 25, 2007 1:51 am UTC

Anpheus wrote:(and honestly, if you're editing code with a box that doesn't have regex to do the reverse, what the fuck development environment are you running there?)

That will mess up any spaces being used for alignment.
Rysto
 
Posts: 1433
Joined: Wed Mar 21, 2007 4:07 am UTC

Re: Tabs vs Spaces

Postby Anpheus » Sun Nov 25, 2007 2:25 am UTC

In which case, I'll fix it. I'm more concerned about consistency than occasional errors. Obviously tabs for indent, spaces for alignment is best. If I need to, I'll change it by hand, but be consistent. I don't want every file I open to require different changes.
Spoiler:
Code: Select all
  /###\_________/###\
  |#################|
  \#################/
   |##┌         ┐##|
   |##  (¯`v´¯)  ##|
   |##  `\ ♥ /´  ##|
   |##   `\¸/´   ##|
   |##└         ┘##|
  /#################\
  |#################|
  \###/¯¯¯¯¯¯¯¯¯\###/
User avatar
Anpheus
I can't get any worse, can I?
 
Posts: 860
Joined: Fri Nov 16, 2007 10:38 pm UTC
Location: A privileged frame of reference.

Re: Tabs vs Spaces

Postby Dingbats » Sun Nov 25, 2007 3:07 pm UTC

I'm currently using four space (as in space) indents when writing Python, but after reading this I'll likely use tabs in the future. Oh, and 80 chars width.
User avatar
Dingbats
 
Posts: 921
Joined: Tue Mar 20, 2007 12:46 pm UTC
Location: Sweden

Re: Tabs vs Spaces

Postby zenten » Sun Nov 25, 2007 4:14 pm UTC

What are people talking about when they say "alignment" anyway?
zenten
 
Posts: 3796
Joined: Fri Jun 22, 2007 7:42 am UTC
Location: Ottawa, Canada

Re: Tabs vs Spaces

Postby EvanED » Sun Nov 25, 2007 5:36 pm UTC

zenten wrote:What are people talking about when they say "alignment" anyway?

We've had that discussion before. It's sorta in the wrong thread, but oh well, such is life. ;-)
EvanED
 
Posts: 4035
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI

Re: Tabs vs Spaces

Postby Anpheus » Sun Nov 25, 2007 5:37 pm UTC

For example:
Code: Select all
int func(long variable_name, long variable_name_two, long variable_name_three,
_ _ _ _ _long variable_name_four, long...

That's with spaces to align the top and bottom lines.

Now it gets really terrible if you use tabs, let's say I use a 4-space tab and use tabs:

Code: Select all
int func(long variable_name, long variable_name_two, long variable_name_three,
--->_ _ _long variable_name_four, long...


Still works on my computer. But somebody else opens it with an eight space tab:

Code: Select all
int func(long variable_name, long variable_name_two, long variable_name_three,
------->_ _ _long variable_name_four, long...


Looks awful.

In addition, I could use two tabs instead of 1 on my screen and then it'd be twice as far off. Basically, tabs and spaces should only be used like so:
Code: Select all
class foo {
--->
--->void foo() { }
--->
--->int func(long variable_name, long variable_name_two, long variable_name_three,
--->_ _ _ _ _long variable_name_four, long variable_name_five) {
--->--->for (int i = 0; i < 10; i++) {
--->--->--->bar fubar = new bar(5, //argument 1
--->--->---> _ _ _ _ _ _ _ _ _ _"six", //argument 2
--->--->---> _ _ _ _ _ _ _ _ _ _7.0, //argument 3
--->--->---> _ _ _ _ _ _ _ _ _ _'\7'); //argument 4
--->--->}
--->}
}


Tabs to bring you up to the current level of indentation, that way anyone can set tabs to as many characters as they prefer, and spaces to line up two lines of code. And -do not- line up code between different levels of indentation.
Spoiler:
Code: Select all
  /###\_________/###\
  |#################|
  \#################/
   |##┌         ┐##|
   |##  (¯`v´¯)  ##|
   |##  `\ ♥ /´  ##|
   |##   `\¸/´   ##|
   |##└         ┘##|
  /#################\
  |#################|
  \###/¯¯¯¯¯¯¯¯¯\###/
User avatar
Anpheus
I can't get any worse, can I?
 
Posts: 860
Joined: Fri Nov 16, 2007 10:38 pm UTC
Location: A privileged frame of reference.

Re: Tabs vs Spaces

Postby Ephphatha » Mon Nov 26, 2007 1:41 am UTC

crazyjimbo wrote:On a related note, I hope everyone agrees that tabs should be 4 spaces :P


Dingbats wrote:I'm currently using four space (as in space) indents when writing Python, but after reading this I'll likely use tabs in the future. Oh, and 80 chars width.


I have my editor set up so that hitting tab gives me fours spaces. That way I can indent my code and be sure that it won't fuck up when I open it in any other editor. Or, god forbid, if I ever subject someone else to the horror that is my code.

(79 char width though, some editors wrap the 80th character to a new line).
I'm not lazy, I'm just getting in early for Christmas is all...
User avatar
Ephphatha
 
Posts: 625
Joined: Sat Sep 02, 2006 9:03 am UTC
Location: Bathurst, NSW, Australia

Re: Tabs vs Spaces

Postby Dongorath » Mon Nov 26, 2007 2:24 pm UTC

Definitely tabs (4 spaces wide), no alignement, 120 chars per line.

Tabs because I'm used to them (and don't like having to press backspace 4 times to go back down 1 tab).

No alignement because I think that a single tab do the trick :
Code: Select all
protected virtual void myFun(object myFirstArgumentWichIsAnObjectAndHasAVeryLongName,
--->object mySecondArgumentWichIsAnObjectAndHasAVeryLongName)
{
--->if (test1
--->--->&& test2)
--->{
--->--->[blah blah blah]
--->}
}


120 chars per line because I use wide screens on a graphical interface (fill nicely on a 17" monitor, a little bit more than half the screen on a wide 24" screen).

And I agree that people that aren't consistent must spend an eternity burning in hell (or whatever equivalent in the religion of your choice).

And above all, I can't stand trailing white characters... But that's just me...
Dongorath
 
Posts: 93
Joined: Tue Oct 16, 2007 1:17 pm UTC

Re: Tabs vs Spaces

Postby enk » Mon Nov 26, 2007 3:26 pm UTC

Dongorath wrote:(and don't like having to press backspace 4 times to go back down 1 tab).


Lol @ ur editor :)

In vim you increase/decrease indenting in steps of your own choosing (e.g. 4). It doesn't matter where on the line the cursor is, you just press << or >>. Or, if you want the current code block indented: >iB (means "indent inner block"). Or you can just select a number of lines and then < and > them.

But of course there's autoindenting, so manual indenting isn't needed that much. The = operator even indents lines according to the autoindent feature. That means: paste som crappy formatted code, press gg=G (re-indent whole buffer) and profit!

I can't say how you do it in other editors, because I don't need others :P
phlip wrote:Ha HA! Recycled emacs jokes.
User avatar
enk
 
Posts: 754
Joined: Mon Sep 10, 2007 12:20 am UTC
Location: Aalborg, Denmark

Re: Tabs vs Spaces

Postby Kizyr » Mon Nov 26, 2007 3:40 pm UTC

For documents, tabs for obvious reasons. Documents don't use monospaced fonts, and indentation is the purpose there.

For code, always spaces. Tabs irritate the hell out of me in code. Making readable code means aligning things in a certain way, and tabs = inconsistent alignment, particularly since code should be in monospaced font anyway.

Also, I use 3 spaces for tabs and indentation in code. KF
~Kaiser
Image
User avatar
Kizyr
 
Posts: 2070
Joined: Wed Nov 15, 2006 4:16 am UTC
Location: Virginia

Re: Tabs vs Spaces

Postby headprogrammingczar » Mon Nov 26, 2007 4:45 pm UTC

I personally use alternating tabs and spaces, and end all my sentances with semicolons;;



I also add random spaces in inconvenient places and exploit the use of plurality in sentances;;;
<quintopia> You're not crazy. you're the goddamn headprogrammingspock!
<Weeks> You're the goddamn headprogrammingspock!
<Cheese> I love you
User avatar
headprogrammingczar
 
Posts: 3015
Joined: Mon Oct 22, 2007 5:28 pm UTC
Location: Beaming you up

Re: Tabs vs Spaces

Postby Amnesiasoft » Mon Nov 26, 2007 5:37 pm UTC

Kizyr wrote:For code, always spaces. Tabs irritate the hell out of me in code. Making readable code means aligning things in a certain way, and tabs = inconsistent alignment, particularly since code should be in monospaced font anyway.

Then you obviously don't know how to use tabs. Tabs are made for indenting because they can be set to whatever size the reader wants. Spaces are use for alignment for the EXACT SAME REASON you use tabs for indenting. Mix them together for ultimate profit!
User avatar
Amnesiasoft
 
Posts: 2575
Joined: Tue May 15, 2007 4:28 am UTC
Location: Colorado

Re: Tabs vs Spaces

Postby Anpheus » Mon Nov 26, 2007 7:05 pm UTC

Dongorath wrote:Definitely tabs (4 spaces wide), no alignement, 120 chars per line.

Tabs because I'm used to them (and don't like having to press backspace 4 times to go back down 1 tab).

No alignement because I think that a single tab do the trick :
Code: Select all
protected virtual void myFun(object myFirstArgumentWichIsAnObjectAndHasAVeryLongName,
--->object mySecondArgumentWichIsAnObjectAndHasAVeryLongName)
{
--->if (test1
--->--->&& test2)
--->{
--->--->[blah blah blah]
--->}
}


120 chars per line because I use wide screens on a graphical interface (fill nicely on a 17" monitor, a little bit more than half the screen on a wide 24" screen).

And I agree that people that aren't consistent must spend an eternity burning in hell (or whatever equivalent in the religion of your choice).

And above all, I can't stand trailing white characters... But that's just me...


HERETIC!

There's a problem with your definition of alignment. You aren't aligning anything except by coincidence ("if (" is four characters, but "while (" is seven.) If you were aligning text, you would end up with horrible, horrible looking code to other people whose tabs are set differently.

For example:
Code: Select all
------->if (test1
------->------->&& test2)

Code: Select all
->if (test1
->->&& test2)


Using spaces you get a perfect result no matter what tab setting you use:

Code: Select all
->if (test1
-> _ _&& test2)

Code: Select all
-->if (test1
--> _ _&& test2)

Code: Select all
---->if (test1
----> _ _&& test2)

Code: Select all
-------->if (test1
--------> _ _&& test2)
Spoiler:
Code: Select all
  /###\_________/###\
  |#################|
  \#################/
   |##┌         ┐##|
   |##  (¯`v´¯)  ##|
   |##  `\ ♥ /´  ##|
   |##   `\¸/´   ##|
   |##└         ┘##|
  /#################\
  |#################|
  \###/¯¯¯¯¯¯¯¯¯\###/
User avatar
Anpheus
I can't get any worse, can I?
 
Posts: 860
Joined: Fri Nov 16, 2007 10:38 pm UTC
Location: A privileged frame of reference.

Re: Tabs vs Spaces

Postby EvanED » Mon Nov 26, 2007 7:18 pm UTC

Anpheus wrote:There's a problem with your definition of alignment. You aren't aligning anything except by coincidence ("if (" is four characters, but "while (" is seven.)

That's why he said no alignment.

I agree that the properly-aligned code looks better.
EvanED
 
Posts: 4035
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI

Re: Tabs vs Spaces

Postby zenten » Mon Nov 26, 2007 7:34 pm UTC

EvanED wrote:
zenten wrote:What are people talking about when they say "alignment" anyway?

We've had that discussion before. It's sorta in the wrong thread, but oh well, such is life. ;-)


Tabs align that just fine. In fact, that's the whole point of tabs, otherwise you just have a macro for a set number of spaces, which is much less useful.
zenten
 
Posts: 3796
Joined: Fri Jun 22, 2007 7:42 am UTC
Location: Ottawa, Canada

Re: Tabs vs Spaces

Postby EvanED » Mon Nov 26, 2007 7:38 pm UTC

zenten wrote:Tabs align that just fine. In fact, that's the whole point of tabs, otherwise you just have a macro for a set number of spaces, which is much less useful.

No they don't. Did you read the post Anpheus just posted, like 30 minutes ago, in this very thread?

If you are using tabs for alignment, things will align at exactly one tab setting, and this setting differs between control constructs and what you are trying to align. "Coincidentally", that setting is exactly the number of spaces that should have been inserted instead of a tab.
EvanED
 
Posts: 4035
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI

Re: Tabs vs Spaces

Postby Anpheus » Mon Nov 26, 2007 7:41 pm UTC

How is it 'less useful.' The difference between spaces and tabs here is fairly arbitrary.
Spoiler:
Code: Select all
  /###\_________/###\
  |#################|
  \#################/
   |##┌         ┐##|
   |##  (¯`v´¯)  ##|
   |##  `\ ♥ /´  ##|
   |##   `\¸/´   ##|
   |##└         ┘##|
  /#################\
  |#################|
  \###/¯¯¯¯¯¯¯¯¯\###/
User avatar
Anpheus
I can't get any worse, can I?
 
Posts: 860
Joined: Fri Nov 16, 2007 10:38 pm UTC
Location: A privileged frame of reference.

Re: Tabs vs Spaces

Postby zenten » Mon Nov 26, 2007 7:50 pm UTC

EvanED wrote:
zenten wrote:Tabs align that just fine. In fact, that's the whole point of tabs, otherwise you just have a macro for a set number of spaces, which is much less useful.

No they don't. Did you read the post Anpheus just posted, like 30 minutes ago, in this very thread?

If you are using tabs for alignment, things will align at exactly one tab setting, and this setting differs between control constructs and what you are trying to align. "Coincidentally", that setting is exactly the number of spaces that should have been inserted instead of a tab.


It hasn't in any editors I've tried this with.
zenten
 
Posts: 3796
Joined: Fri Jun 22, 2007 7:42 am UTC
Location: Ottawa, Canada

Re: Tabs vs Spaces

Postby Anpheus » Mon Nov 26, 2007 8:13 pm UTC

What are you talking about? Open up Notepad++ or any editor that lets you configure tab size.

Switch to a 4 space tab.

Type:
Code: Select all
if (x
--->&& y)

The ---> is a tab.

Then switch to an eight space tab. You get:
Code: Select all
if (x
------->&& y)



It's no longer aligned.
Spoiler:
Code: Select all
  /###\_________/###\
  |#################|
  \#################/
   |##┌         ┐##|
   |##  (¯`v´¯)  ##|
   |##  `\ ♥ /´  ##|
   |##   `\¸/´   ##|
   |##└         ┘##|
  /#################\
  |#################|
  \###/¯¯¯¯¯¯¯¯¯\###/
User avatar
Anpheus
I can't get any worse, can I?
 
Posts: 860
Joined: Fri Nov 16, 2007 10:38 pm UTC
Location: A privileged frame of reference.

Re: Tabs vs Spaces

Postby zenten » Mon Nov 26, 2007 8:19 pm UTC

Anpheus wrote:What are you talking about? Open up Notepad++ or any editor that lets you configure tab size.

Switch to a 4 space tab.

Type:
Code: Select all
if (x
--->&& y)

The ---> is a tab.

Then switch to an eight space tab. You get:
Code: Select all
if (x
------->&& y)



It's no longer aligned.


Oh!

Ok, I didn't get what you were saying.

Simple solution really:

if<tab>(x
<tab>&& y)
zenten
 
Posts: 3796
Joined: Fri Jun 22, 2007 7:42 am UTC
Location: Ottawa, Canada

Re: Tabs vs Spaces

Postby Anpheus » Mon Nov 26, 2007 8:38 pm UTC

Which doesn't work everywhere and for everything. For example, a while block at an eight space tab versus four space tab:

Eight space tab:
Code: Select all
Tab boundaries:
-------|-------|
while-->(
------->&&stuff


Four space tab:
Code: Select all
Tab boundaries:
---|---|---|---|
while-->(
--->&&stuff


As you can see, while being five characters long exceeds a tab boundary, causing misalignment.

C++ keywords sorted by length:
Code: Select all
do
if
asm
for
new
try
auto
case
else
enum
goto
this
TRUE
void
break
catch
class
const
FALSE
throw
union
using
while
delete
export
extern
friend
inline
public
return
signed
sizeof
static
struct
switch
typeid
default
mutable
private
typedef
virtual
continue
explicit
operator
register
template
typename
unsigned
volatile
namespace
protected
const_cast
static_cast
dynamic_cast
reinterpret_cast


If you use an eight space tab, your code will fuck up anything at or longer than eight characters. That's fourteen different keywords. At a four space tab, you'd fuck up forty-nine different keywords. At a three space tab, all but two.

And that's not counting alignment with typedefs, variables, and classes. I think your code probably uses those.
Spoiler:
Code: Select all
  /###\_________/###\
  |#################|
  \#################/
   |##┌         ┐##|
   |##  (¯`v´¯)  ##|
   |##  `\ ♥ /´  ##|
   |##   `\¸/´   ##|
   |##└         ┘##|
  /#################\
  |#################|
  \###/¯¯¯¯¯¯¯¯¯\###/
User avatar
Anpheus
I can't get any worse, can I?
 
Posts: 860
Joined: Fri Nov 16, 2007 10:38 pm UTC
Location: A privileged frame of reference.

Re: Tabs vs Spaces

Postby TomBot » Mon Nov 26, 2007 9:40 pm UTC

Mmm, this should have been a poll. Still, I'm glad to see that most of you agree with me, and are thus smart. Tabs for indentation, spaces for further alignment, if you must.

I think one's opinion on this can tell you how pedantic a person is. The key advantage of tabs is semantic clarity: indenting and aligning convey different information, so it makes sense to use a different symbol. Otherwise, what's '\t' even for? The disadvantage is that it falls apart if people don't use it conscientiously. Now, as a pedant, I think the latter is irrelevant - people should use it conscientiously, and if they don't, let them suffer.

Compilers demand everything be perfect. You can react in two ways: either you get pissed off about it, and just keep compiling your imperfect code over and over until it works, or you accept it, and try to be disciplined. People who are willing to accept the discipline necessary to indent properly with tabs, even though it won't actually break anything if the code is ugly, are more likely to take the second approach to the strict requirements of programming, and thus are more likely to be better coders. (Correlation does not imply causation.)
User avatar
TomBot
 
Posts: 228
Joined: Sun Jul 29, 2007 1:17 am UTC
Location: Illinois (UIUC)

Re: Tabs vs Spaces

Postby enk » Mon Nov 26, 2007 11:55 pm UTC

I agree, spaces for alignment. But hey, spaces for indentation too.

The problem in having your editor showing tabs as 4 spaces is that it won't look the same in another guys editor! And this is important if you're concerned about your code maxing at 80 cols...
phlip wrote:Ha HA! Recycled emacs jokes.
User avatar
enk
 
Posts: 754
Joined: Mon Sep 10, 2007 12:20 am UTC
Location: Aalborg, Denmark

Re: Tabs vs Spaces

Postby EvanED » Tue Nov 27, 2007 12:03 am UTC

enk wrote:I agree, spaces for alignment. But hey, spaces for indentation too.

The problem in having your editor showing tabs as 4 spaces is that it won't look the same in another guys editor!

I vote this as a feature, not bug.

And this is important if you're concerned about your code maxing at 80 cols...

Nah, not really. Just redefine "lines should be less than 80 characters" as "lines should be less than 80 characters with a 4-character tab stop."

If someone using an 8-character stop has to deal with lines longer than 80 characters, then too bad; he can just set it to 4-character stops, and you're almost no worse off than if you had used spaces in the first place. (In fact, if this person is editing the code, he'd probably need to change settings anyway if you used spaces, lest he start inserting 8 of them where there should only be 4.) At least with tabs you've given him a choice of (1) not worrying about the 80-col limit, (2) saying that his preference for 8-space tabs overrides his preferences for 80-col limits and leaving the settings the same, and (3) saying his preference for 80-col limits overrides his preferences for 8-space tabs and changing to shorter tabs.
EvanED
 
Posts: 4035
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI

Re: Tabs vs Spaces

Postby masher » Tue Nov 27, 2007 12:10 am UTC

The editor I use converts tabs to spaces. I use 3 spaces per tab, and I don't have to work on anybody else's code, so it's alright....
masher
 
Posts: 822
Joined: Tue Oct 23, 2007 11:07 pm UTC
Location: Melbourne, Australia

Re: Tabs vs Spaces

Postby Dongorath » Tue Nov 27, 2007 10:32 am UTC

Anpheus wrote:HERETIC!

There's a problem with your definition of alignment. You aren't aligning anything except by coincidence ("if (" is four characters, but "while (" is seven.) If you were aligning text, you would end up with horrible, horrible looking code to other people whose tabs are set differently.


Ok, bad exemple for the if and the four spaces tab, but that's why I said "no alignment". In my exemple, the second argument of my function is in no way aligned to the first one. That's why I said no alignment, just one more tab. Two if you really want to distinguish it from the subsequent indented block/line of code...
Dongorath
 
Posts: 93
Joined: Tue Oct 16, 2007 1:17 pm UTC

Re: Tabs vs Spaces

Postby fryman » Tue Nov 27, 2007 5:06 pm UTC

I'm at uni, so it is just myself that works on my code. Also, my TA uses the same IDE I do (VS 2005 with (mostly) default settings) so I need not worry about inconsistencies between editors. As long as I am consistent in my code (which I am), then I am happy, and so is everyone else. On a side note, my CS 115 prof. uses spaces to pad when she forgets a tab (or rather, destroys one that VS made), which annoys the hell out of me, just like Allman indentation, but that's for that other thread.
Open source sigs? Here, use mine!
User avatar
fryman
 
Posts: 50
Joined: Mon Aug 20, 2007 7:11 pm UTC
Location: In a box, sitting next to a cat.

Next

Return to Religious Wars

Who is online

Users browsing this forum: No registered users and 3 guests