PDA

View Full Version : To TAB or not to TAB...



BillBoeBaggins
01-08-2004, 06:52 PM
If you use tabs as a rule
If you use spaces as a rule

(in regards to code indentation)

axon
01-08-2004, 07:00 PM
I always use TAB in code. It is much simpler, less key strokes, and cleaner looking.

nickname_changed
01-08-2004, 07:26 PM
I use tabs, but have them replaced with spaces (5), so they look the same on all file editors.

major_small
01-08-2004, 07:53 PM
^ that's what I do... plus, when I have to use spaces, I always misalign by a space or so... and when you start nesting more and more stuff, you (I) spend way too much time worrying about exact spacing...

Polymorphic OOP
01-08-2004, 07:58 PM
Spaces. I turn on the "turn tabs into spaces" option in VC++7.1 and set tabs to 2 spaces.

Why?

Because tabs cause all sorts of problems with porting to other IDEs. If you are using one IDE which has tabs set to a certain size but are using code from multiple sources which uses tabs set at other sizes then the formatting goes to hell! Not all IDEs use the same tabbing size by default. Not only that, but on all IDEs I've used, default tabbing is set to be too high anyways (they are usually set to between 4 and 6 spaces wide). If you use the "convert tabs to spaces" option (which inserts spaces instead of tabs when you use the tab key) when you are coding, then this problem never occurs. You are guaranteed that your code will be formatted exactly the way you want it no matter who uses it on whichever IDE they choose.

Thantos
01-08-2004, 08:17 PM
Two spaces is what I use.

ZakkWylde969
01-08-2004, 08:22 PM
My editor mostly does the tabbing for me in a spiffy auto check feature.

dirkduck
01-08-2004, 08:57 PM
I use tabs myself, seems a lot easier than hitting space five times.

incognito
01-08-2004, 09:01 PM
I use tabs.

UnregdRegd
01-08-2004, 09:12 PM
I use spaces, too, for reasons already mentioned. I sometimes wonder how a person can use tabs instead of spaces and still call themselves human!

Zach L.
01-08-2004, 09:13 PM
Two spaces... If auto-indent is available with spaces, I use that (set to 2, of course).

DISGUISED
01-08-2004, 10:01 PM
I use spaces because that is what I am told to use.

alpha
01-08-2004, 10:15 PM
tabs to spaces option with it set to 2 spaces.

DarkViper
01-08-2004, 10:49 PM
TABed, because its less tedious and is good practice if you script in other languages as well.

kinghajj
01-08-2004, 11:01 PM
2 space tabs? Wow! I use 8-space tabs! That does make the code long vertically, but it looks cleaner to me.

though, some of my editor's use 4-space tabs

Brian2
01-09-2004, 01:48 AM
Tabs are 8 characters, and thus indentations are also 8 characters. There are heretic movements that try to make indentations 4 (or even 2!) characters deep, and that is akin to trying to define the value of PI to be 3.

Rationale: The whole idea behind indentation is to clearly define where a block of control starts and ends. Especially when you've been looking at your screen for 20 straight hours, you'll find it a lot easier to see how the indentation works if you have large indentations.

Now, some people will claim that having 8-character indentations makes the code move too far to the right, and makes it hard to read on a 80-character terminal screen. The answer to that is that if you need more than 3 levels of indentation, you're screwed anyway, and should fix your program.

In short, 8-char indents make things easier to read, and have the added benefit of warning you when you're nesting your functions too deep. Heed that warning.

Polymorphic OOP
01-09-2004, 01:56 AM
Originally posted by Brian2
Tabs are 8 characters, and thus indentations are also 8 characters. There are heretic movements that try to make indentations 4 (or even 2!) characters deep, and that is akin to trying to define the value of PI to be 3.

Rationale: The whole idea behind indentation is to clearly define where a block of control starts and ends. Especially when you've been looking at your screen for 20 straight hours, you'll find it a lot easier to see how the indentation works if you have large indentations.

Now, some people will claim that having 8-character indentations makes the code move too far to the right, and makes it hard to read on a 80-character terminal screen. The answer to that is that if you need more than 3 levels of indentation, you're screwed anyway, and should fix your program.

In short, 8-char indents make things easier to read, and have the added benefit of warning you when you're nesting your functions too deep. Heed that warning.

haha, I really hope that was a joke.

Brian2
01-09-2004, 02:05 AM
haha, I really hope that was a joke.

http://pantransit.reptiles.org/prog/CodingStyle.html

Polymorphic OOP
01-09-2004, 02:12 AM
*shudders*

I'm so glad I don't follow that convention

adrianxw
01-09-2004, 04:06 AM
I have auto indent set to 4 spaces, but also have TAB converted to spaces. It is easier to cut and paste into html documents like that.

ober
01-09-2004, 07:19 AM
Tab here... why would you use spaces? More keystrokes, have to keep track of how many... just tab it. *BAM* or *BAM BAM* and everything is lined up.

DrakkenKorin
01-09-2004, 07:34 AM
you poll lacks an "other" option.

I neither tab nor space. I indent.

::lifting nose higher and higher...::

adrianxw
01-09-2004, 07:53 AM
>>> ::lifting nose higher and higher...::

Is that a bogie I see up there?

Ober:

>>> Tab here... why would you use spaces?

You press Tab as normal, but you tell your IDE that when you press TAB it is to inesert 4 spaces. Thus no additional keystrokes are required, and no fiddling about is needed if you cut and paste a bit of code into another IDE or into NotePad for example.

DrakkenKorin
01-09-2004, 08:32 AM
>>Is that a bogie I see up there?<<

NO, ITS PIERCED!

BillBoeBaggins
01-09-2004, 10:52 AM
DrakkenKorin:
.................... "other"?:)
Polymorphic OOP:
I didn't know that option existed (space replace tab thingy), but I don't use VC I only use Dev-C++.

I try to use tabs, and I have my tab set to 4 spaces, but I don't want the extra job of making sure I hit the spacebar 4 times when I can hit the TAB once. But yes, maybe I will make a cpp process script that converts TAB's to 4 Spaces in the file.

Thantos
01-09-2004, 11:30 AM
More keystrokes, have to keep track of how many
VIM does it for me. I find two spaces much easier to read.


Tabs are 8 characters
IIRC tabs are actually 5 characters, its been that way since the days of typewriters. Set your word processor to a fixed width font and try it out. Its 5 characters. So the arguement that it is 8 characters and not 4, 2, 12, or pi is bull$$$$.

alpha
01-09-2004, 12:28 PM
Originally posted by BillBoeBaggins
DrakkenKorin:
.................... "other"?:)
Polymorphic OOP:
I didn't know that option existed (space replace tab thingy), but I don't use VC I only use Dev-C++.

I try to use tabs, and I have my tab set to 4 spaces, but I don't want the extra job of making sure I hit the spacebar 4 times when I can hit the TAB once. But yes, maybe I will make a cpp process script that converts TAB's to 4 Spaces in the file. Dev-C++ should also have that option.

golfinguy4
01-09-2004, 02:42 PM
I use five spaces.

Speedy5
01-09-2004, 02:51 PM
Three spaces with the tab-to-space feature (which also allows shift-tab).

Lurker
01-09-2004, 04:15 PM
I use tabs. I know the problems associated with them, but they look better to me, and are easier to get rid of / add. Who's gonna read MY code, anyway :D ?

gcn_zelda
01-09-2004, 06:34 PM
I use 5 space tabs. Dunno why. I guess I'm just lazy.

Sang-drax
01-09-2004, 07:24 PM
Originally posted by Thantos
IIRC tabs are actually 5 characters, its been that way since the days of typewriters. Set your word processor to a fixed width font and try it out. Its 5 characters.
No, it's not. The number of characters used depends on what font size you're using. At least that's the case in Word 2002.

Sang-drax
01-09-2004, 07:43 PM
And as for tab sizes, the standard is 8 spaces, nothing else.
In some programming languages this is part of the language definition (Python and Haskell for example).
I use a tabstop of four spaces though.

SirCrono6
01-09-2004, 09:09 PM
Spaces all the way! Two spaces all the way!



#include <iostream>

int main( void )
{
std :: cout << "Hello World!" << std :: endl;
return 0;
}


- SirCrono6

Stoned_Coder
01-09-2004, 09:10 PM
Am I the only one who uses three space tabs then? I think 3 is perfect for readability.

Speedy5
01-09-2004, 10:28 PM
Originally posted by Speedy5
Three spaces with the tab-to-space feature (which also allows shift-tab).
Leeme quote myself. :D

3 is perfect as it is in many other cases

major_small
01-09-2004, 10:46 PM
i have tab set to four spaces becuase of cout... example:
cout<<"blah blah blah blah"<<endl
<<"second line blah blah blah"<<endl;

bludstayne
01-09-2004, 11:57 PM
When I first saw the post I was excited, thinking it was a music discussion. I do have to say I am disappointed!:p

Brian2
01-10-2004, 06:30 AM
Originally posted by SirCrono6
Spaces all the way! Two spaces all the way!



#include <iostream>

int main( void )
{
std :: cout << "Hello World!" << std :: endl;
return 0;
}


- SirCrono6

There is no reason to use int main(void) in c++
int main() is exactly the same.

Lurker
01-10-2004, 10:00 AM
Originally posted by Brian2
There is no reason to use int main(void) in c++
int main() is exactly the same.

Then why waste the time to question it?

SirCrono6
01-10-2004, 11:00 AM
Yeah, I know. I don't normally use it anyway :D.



int main(int argc, char *argv[])


All the way!

- SirCrono6

Thantos
01-10-2004, 11:48 AM
There is no reason to use int main(void) in c++
int main() is exactly the same.
Brian2 would you please stop posting crap. Thank you
http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1044841143&id=1043284376

Grayson_Peddie
01-10-2004, 01:26 PM
...I have Visual C# .net set to 4 spaces and I use Virtual Spaces because if I'm going to be posting a code in the forum, Visual C# .net converts from tabs to spaces. I also use tabs to line up the code. For example:


using System;
using System.Drawing;
using System.Windows.Forms;

namespace Example
{
/// <summary>
/// Main class for the form
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// Constructor for a Windows Form class
/// </summary>
public Form1()
{
InitializeComponents()
}

/// <summary>
/// Used for initializing a form and all the controls needed
/// for the application.
/// </summary>
public void InitializeComponents()
{
//
// form1
//
this.Text = "Form 1 Example";
this.BackColor = System.Drawing.Color.Black;
// ...
}

/// <summary>
/// Entry point for starting an application.
/// </summary>
public static void Main(string[] args)
{
Application.Run(form1);
}
}
}

Benzakhar
01-10-2004, 01:47 PM
many editors treat tabs and spaces the same way. E.g. if you have 4 spaces and press backspace they all get deleted. If you have 1 one tab and set it to be the size of 4 spaces then it will do the samething. The only difrence is that with spaces you can click everywhere and the caret will be positioned there but with tabs it will be positioned to the begining or end of the tab. Some people (like me) are just to lazy to change the setting becuase of this.

Thantos
01-10-2004, 03:17 PM
The number of characters used depends on what font size you're using
Yeah after looking at it some more I realize its actually going to the same spot of the paper.

But if you do put in to Courier New 12pt which is the closest to the typeface that most typewriters used it is 5 spaces which is actually what my point was about :)

I think most of us use spaces regardless (or should it be irregardless?) if we get them by hitting the spacebar or having tabs set to insert spaces instead of the tab character.

Zach L.
01-10-2004, 06:49 PM
Originally posted by Thantos
or should it be irregardless?
That word doesn't exist.

gcn_zelda
01-10-2004, 07:09 PM
Originally posted by Zach L.
That word doesn't exist.

That's irirelevant.

Thantos
01-10-2004, 07:51 PM
Originally posted by Zach L.
That word doesn't exist.


www.spellcheck.com
One entry found for irregardless.
Main Entry: ir·re·gard·less
Pronunciation: "ir-i-'gärd-l&s
Function: adverb
Etymology: probably blend of irrespective and regardless
Date: circa 1912
nonstandard : REGARDLESS
usage Irregardless originated in dialectal American speech in the early 20th century. Its fairly widespread use in speech called it to the attention of usage commentators as early as 1927. The most frequently repeated remark about it is that "there is no such word." There is such a word, however. It is still used primarily in speech, although it can be found from time to time in edited prose. Its reputation has not risen over the years, and it is still a long way from general acceptance. Use regardless instead.

Granted it said that regardless is what should be used but just to counter the doesn't exist comment :)

But yeah I'm not very good in the proper grammer area.

bludstayne
01-10-2004, 09:31 PM
eyem naught da bestest spellar en tha wourld.