Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » To tab or not to tab?

This thread is locked; no one can reply to it. rss feed Print
 1   2   3 
To tab or not to tab?
Michael Jensen
Member #2,870
October 2002
avatar

So where I work, we're adopting some coding standards, one of them is to not use tabs -- aparently because people don't know how to use them properly or are too lazy too something... -- it just seems kinda ridiculous to me that I'm going to have to start using spaces instead, boss keeps saying there are all kinds of arguments for not using tabs and none for using them...

Isn't this more of a there arn't any arguments for breathing either -- you just do it -- sorta thing? Or is there really a good reason not to use tabs?

Also, if anyone has a killer reason to use tabs over spacing, let me know, I'd love to hear it -- what are the opinions on a.cc?

Onewing
Member #6,152
August 2005
avatar

Quote:

aparently because people don't know how to use them properly or are too lazy too something...

??? So people DO know how to use spaces properly?

I think this is pretty retarded. I'd just keeping using tabs and write a program to replace all tabs with X many spaces if I had to. :-/

[edit]
I think, maybe, some development suites can do this as well.

------------
Solo-Games.org | My Tech Blog: The Digital Helm

Kikaru
Member #7,616
August 2006
avatar

Tabs are much faster, and generally more consistent. I only use spaces to indent when tab is way to big, or I can't use tabs (like on forums, AKA, here).

Thomas Fjellstrom
Member #476
June 2000
avatar

I like tabs for indentation. A good editor lets you configure the number of spaces they appear as, and a tab is a SINGLE character, you can properly navigate through indentation in any code, in any editor, because a 3 level indentation is 3 tabs, not 9, 12 or 24 spaces ::)

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

bamccaig
Member #7,536
July 2006
avatar

<cough>A tab is equivalent to 4 spaces for coding purposes</cough>

I would just keep using tabs... If you must, replace them with spaces when you're finished.

nonnus29
Member #2,606
August 2002
avatar

Huh? Isn't a \t always 8 spaces no matter what? And when you config your editor its actually putting X space in place of \t?

Thomas Fjellstrom
Member #476
June 2000
avatar

Quote:

Huh? Isn't a \t always 8 spaces no matter what? And when you config your editor its actually putting X space in place of \t?

Actually, it aligns to a X space wide column. If you have:

foo\t

and 4 space wide tabs, your cursor shows up one character away from the last o.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Michael Jensen
Member #2,870
October 2002
avatar

we're all using visual studio... which will convert tabs into spaces if you tell it to.

you can also tell it to display tabs as any amount of spacing as you want.

I complain, well in other editors you just have to hit backspace once -- or in msvs -- but in msvs you can shift-tab backwards still -- they say "oh blah blah blah, we're not using other editors" -- so I ask for the argument for using spaces and they say "oh a lot of other editors don't display tabs right -- like word."

like hell they don't.

edit:

also, nonnus, in most editors a tab is 4 spaces, notepad is the only one that uses 8 that I know of off the top of my head -- and tf is right, they align to columns, and pressing right arrow three times as opposed to 12 is a bit easier for most people...

Jakub Wasilewski
Member #3,653
June 2003
avatar

Quote:

there are all kinds of arguments for not using tabs and none for using them...

My single argument for using tabs is that many people can work on the codebase at once and each can set his own indentation size according to his preference. With spaces, you get one normalized indentation size.

Also, if you use spaces, most editors won't allow you to easily drop a level of indentation when it's not needed anymore - and those that do will need to guess where the next higher indentation level is. This guessing process often doesn't work perfectly.

I'd say it's the other way around - I'd be hard-pressed to find any sort of reason against using tabs. About the only thing that comes to mind is that it can turn into a mess if you mix tabs and spaces to line up something, and someone tries to read that with a different tab setting. That's easily avoided, though.

EDIT:

Quote:

oh a lot of other editors don't display tabs right -- like word.

Who the hell would want to use Word of all things to edit source code?

---------------------------
[ ChristmasHack! | My games ] :::: One CSS to style them all, One Javascript to script them, / One HTML to bring them all and in the browser bind them / In the Land of Fantasy where Standards mean something.

Thomas Fjellstrom
Member #476
June 2000
avatar

Quote:

I'd say it's the other way around - I'd be hard-pressed to find any sort of reason against using tabs. About the only thing that comes to mind is that it can turn into a mess if you mix tabs and spaces to line up something, and someone tries to read that with a different tab setting.

This is the only arument against tabs I'd accept. Bus as you say, the problem is easily avoided.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Kitty Cat
Member #2,815
October 2002
avatar

Quote:

About the only thing that comes to mind is that it can turn into a mess if you mix tabs and spaces to line up something, and someone tries to read that with a different tab setting.

Quite a big reason, IMO. Some people can be quite religious about their tab size, and when things get all mixed up, trying to look through the code becomes a royal PITA.

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Thomas Fjellstrom
Member #476
June 2000
avatar

Quote:

Quite a big reason, IMO. Some people can be quite religious about their tab size, and when things get all mixed up, trying to look through the code becomes a royal PITA.

And it matters how? So long as its readable. And what exactly are you doing that you need things to line up perfectly, that arent using tabs? QUIT MIXING TABS AND SPACES!

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Kitty Cat
Member #2,815
October 2002
avatar

Quote:

And it matters how? So long as its readable.

Which is the problem.. it's not. :P

Quote:

And what exactly are you doing that you need things to line up perfectly, that arent using tabs? QUIT MIXING TABS AND SPACES!

When you're working on a project with multiple people, you can't gaurantee everyone will do that. It's easier to say "no tabs" than "tabs are okay, just don't mix them with spaces or other characters".

In my own projects where I'm the only one working on it, I tend to use tabs. But then, I also know how to do stuff like this:

int main(int argc)
{
    if(argc > 1)                              // Print the number of args
        printf("You passed %d args\n", argc); // the user passed
    return 0;
}

without screwing it up with tabs. :P

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Thomas Fjellstrom
Member #476
June 2000
avatar

Quote:

without screwing it up with tabs. :P

Don't do that?

Quote:

When you're working on a project with multiple people, you can't gaurantee everyone will do that.

Sure you can. Its called a style guide. If it isn't followed, a person gets commit privilegs revoked (or fired, whichever the case may be).

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Peter Wang
Member #23
April 2000

Just use spaces. So you won't necessarily see the code with your preferred indent size, suck it up. Most people prefer reasonable indent sizes such as 2, 3, 4 or 8 chars. You can get used to any of them.

If you use spaces, your code will look the same no matter if it's in an email client, in the middle of a diff (with the extra +- chars at the front), thrown up on the web, viewed on the terminal with standard tools like cat and less, etc.

Matthew Leverton
Supreme Loser
January 1999
avatar

Tabs are better.

Thomas Fjellstrom
Member #476
June 2000
avatar

Quote:

If you use spaces, your code will look the same no matter if it's in an email client, in the middle of a diff

Don't care. Actually editing the code is what I care about. And using spaces mucks that up.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Michael Jensen
Member #2,870
October 2002
avatar

Quote:

When you're working on a project with multiple people, you can't gaurantee everyone will do that. It's easier to say "no tabs" than "tabs are okay, just don't mix them with spaces or other characters".

You'd have to be too retarted to wipe your own ass to not understand that you can't mix tabs with spaces. Just use tabs, they work everywhere, they look fine everywhere, if multiple people are working on the same file, so long as their all using tabs you end up with zero problems, you get a smaller file size, and the files are easier to work with in every circumstance.

Matthew Leverton
Supreme Loser
January 1999
avatar

But you can mix tabs and spaces. Tabs are for indenting. Spaces are for lining up.

-T- is a tab; . is a space.

if ()
{
--T--foo();...// comment
--T--blah();..// comment.
}

Works great.

Karadoc ~~
Member #2,749
September 2002
avatar

I stopped using tabs for coding many years ago. The reason I don't use them is that it often messes up the indentation of code that is worked on by more than one person. For example, it is common for people to sometimes use spaces to make the position of a common look nicer, or to make long commands spread over multiple lines in a nice way.

if (we_want_to_do_stuff)
{ // stuff inside the if is tabbed
  variables =
    long_html_function(stuff.sub_stuff->mother, // immediately after first arg.
                       the_next_argument,       // Comments positioned with spaces
                       other junk,              // in line with other comments.
                       0);                      // the end
}

The spacing of the arguments to line up with one another and the spacing of the comments to line up at the end of the first argument - that all gets completely messed up if the size of the tabs at the start of the line is different. So I use spaces instead of tabs. As for the "tabs are faster" argument, there is absolutely no difference for me, as it is easy to setup gvim to make the tab key play nice.

-----------

Michael Jensen
Member #2,870
October 2002
avatar

Quote:

But you can mix tabs and spaces. Tabs are for indenting. Spaces are for lining up.

-T- is a tab; . is a space.
if ()
{
--T--foo();...// comment
--T--blah();..// comment.
}Works great.

I guess mix is the wrong word, as I don't consider what you're doing "mixing" them perse (though you should still be shot):

--T--foo();...// comment
.....blah();--T--// comment.

that's mixing them -- and if using multiple editors, you will end up with lots of problems -- however, if you use all tabs, or all spaces these problems will NEVER come up for you. (hence, you kill spaces because they're harder to work with.)

/edit (I misenterpreted what karadoc had shown us to be something meaningful)

Goalie Ca
Member #2,579
July 2002
avatar

Thanks to the magic of vim i can use tabs or spaces and have the behaviour and appearance be exactly the same except for using the arrow keys (but vim users use better keys ;))

Quote:

that all gets completely messed up if the size of the tabs at the start of the line is different. So I use spaces instead of tabs.

But i bet you don't use a fixed-width font. Try a different editor and you will understand ;)

-------------
Bah weep granah weep nini bong!

Bob Keane
Member #7,342
June 2006

Quote:

As for the "tabs are faster" argument, there is absolutely no difference for me,

It's faster to press one key once than one key four (or eight) times. It is also more reliable, you don't need to remember if you pressed three or five times. I noticed some editors automatically insert spacing for certain keywords such as if statements or brackets, not sure which.

Quote:

oh a lot of other editors don't display tabs right -- like word

Are they using the show format option in word, and more importantly, why?

By reading this sig, I, the reader, agree to render my soul to Bob Keane. I, the reader, understand this is a legally binding contract and freely render my soul.
If we get apple juice from squeezing apples, and we get prunes from drying out plums, where does prune juice come from?
Hi Randall Monroe.

Karadoc ~~
Member #2,749
September 2002
avatar

Bob Keane said:

It's faster to press one key once than one key four (or eight) times. It is also more reliable, you don't need to remember if you pressed three or five times.

Thank you for that insight, Bob; but if you had bothered to quote the second half of my sentence you may have noticed that your comment wasn't really relevant.
[edit]
To make what I'm talking about a bit more clear, here is a line from my vim.rc file:

set ai et ts=4 sw=4 nohls lbr

This causes vim to use 4 spaces instead a tab character, amongst other things.
[/edit]

Michael Jensen said:

that's mixing them -- and if using multiple editors, you will end up with lots of problems -- however, if you use all tabs, or all spaces these problems will NEVER come up for you. (hence, you kill spaces because they're harder to work with.)

/edit (I misenterpreted what karadoc had shown us to be something meaningful)

Do you think that what I showed was not meaningful after all? I absolutely agree that the problems only arise when tabs and space are mixed, and that's exactly what I wanted to show in my example. In my experience there are cases where tabs are insufficient to get the layout that I want. Tabs do no allow me to line up my arguments in that way without shifting the position of the first argument somewhere away from the open bracket. Rather than sacrifice what I believe is a superior layout for my code by abandoning spacing, I choose to abandon tabs. I do all my coding in gVim, and gVim automatically handles any problems that I might have with spaces. I uses spaces for all my indentation, and I get that indentation with a single key press.

-----------

SiegeLord
Member #7,827
October 2006
avatar

What is important to realize here, is the argument that tabs are different widths on different computers is flawed. Why? Because when you indent using spaces, you are forcing a tab size onto the end user of your code. And since you are forcing the user to use your tab size by using spaces, why not force it by telling the user to change their tab per space ratio, and use tabs? Both are identically annoying. I find much space indented code unreadable, and I'd rather have bad comment formatting in a few isolated spaces, than have the whole 10k+ line source file be afflicted with a 2-space indentation disaster.

E.g. I converted Karadoc ~~'s code to use only tabs. I use 4 space tabs in my editors, while allegro uses 8 spaces per tab. So this code shows how badly the mess up is:

if (we_want_to_do_stuff)
{  // stuff inside the if is tabbed
  variables =
    long_html_function(stuff.sub_stuff->mother,  // immediately after first arg.
            the_next_argument,      // Comments positioned with spaces
            other junk,          // in line with other comments.
            0);              // the end
}

Yes, the comments are messed up. A small price to pay for nicely indented code imho.

Whenever I get code that uses space indentation, I immediately nuke it using AStyle plugin from Code::Blocks which converts everything to tabs.

EDIT: Fixed typos

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

 1   2   3 


Go to: