To tab or not to tab?
Michael Jensen

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
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.

Kikaru

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

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 ::)

bamccaig

<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

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
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.

Michael Jensen

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
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?

Thomas Fjellstrom
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.

Kitty Cat
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.

Thomas Fjellstrom
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!

Kitty Cat
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

Thomas Fjellstrom
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).

Peter Wang

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

Tabs are better.

Thomas Fjellstrom
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.

Michael Jensen
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

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 ~~

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
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

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 ;)

Bob Keane
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?

Karadoc ~~
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

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

Michael Jensen
Quote:

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 )

are you telling me that when you press the backspace key, it deletes four spaces for you? and seriously, wtf.

Quote:

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

tabs look fine in fixed with, or non-fixed with fonts. spaces on the other hand will almost never line up with a non-fixed with font (except from the beginning of the line).

I copied your code into notepad, properly tabbed it, and copied it directly into a.ccs textbox, no problems, and into word with no problems, it works everywhere, I can easily navigate with cursors / backspace, everywhere. -- Anybody can copy and paste this into just about any sane editor, and bam it looks fine.

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
}

of course if you take the SPACES only version and paste it into your favorite document editor for printing AND bam:
.
http://www.allegro.cc/files/attachment/595265

SiegeLord
Quote:

Anybody can copy and paste this into just about any sane editor, and bam it looks fine.

Hehe, here's what it looks like in my editor (converted tabs to spaces to match appearance in my editor):

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
}

Make a guess why? ;) Doesn't change my point though. Better a few messed up comments than a messed up entirety of the source file.

Michael Jensen

shit you're right -- it's the right justification that matters again -- screwed up with spacing, and screwed up with tabs to different sizes

oh well, moral of the story is, use the same damn tab size! :-P

oh, and bonus points: it takes like 3 seconds to fix if you're using tabs... spaces? much longer.

Trezker

I'd say the problem lies in putting comments behind the code. That always gets messed up every time you change one of those lines of code, doesn't matter if you use spaces or tabs.

When you need to comment on a whole slab of code, write a slab of comments above the whole slab of code. Like a sort of pseudocode.

if (we_want_to_do_stuff)
{   
    /*! stuff inside the if is tabbed
        arg1 explanation
        arg2 explanation
        arg3 explanation
        arg4 explanation
    */
    variables = long_html_function(stuff.sub_stuff->mother, the_next_argument, "other junk", 0);
}

Karadoc ~~
Quote:

tabs look fine in fixed with, or non-fixed with fonts. spaces on the other hand will almost never line up with a non-fixed with font (except from the beginning of the line).

That's true. Tabs are better if you intend to code with non-fixed width fonts. But non-fixed with fonts have other issues anyway, so I don't like to use them.
For example, you can't do this:

/*****************************************************
** Here is a big important marker in my code.       **
** I'm surrounding it by stars to make it stand out **
*****************************************************/

So I don't use non-fixed with fonts, and I don't use tabs.

As for the tab version looking alright in "just about any sane editor", I agree that it looks alright, but the fact is that it still isn't formatted the way I actually wanted it to be. The stuff is nicely intended, but it is intended to some arbitrary line. I wanted it to be intended to the start of the open bracket, and I wanted the comments to start at the end of the last argument. Tabs do have some advantages for non-fixed with fonts and stuff like that, but I'm prefer the advantage of being have to format my code the way I like it (which can only be done with fixed with spaces).

I find it interesting that there are so many tab advocates here. I've just asked a couple of people about it at work and they all said they used spaces. The people I asked don't work on programming stuff together, so that is their own personal choice.

alethiophile

I like tabs when I'm using an editor that uses that, but normally when I code I'm using either Emacs or Gobby, both of which just insert some number of spaces when you press <tab>. So I'm fine with either.

Edgar Reynaldo

I can't stand tabs. I use Code::Blocks and whenever I press the tab key it automatically converts a tab press into enough spaces to line up with the next tab alignment column. I use 2 spaces per indentation level and it just annoys me when I have to look at source code that uses tabs since they almost always mix it with spaces so I select and copy a tab , paste it into the replace all dialog and replace it with however many spaces I'm using. I hate tabs so much I think about writing up a patch to contribute for allegro's source code that nukes all the tabs right out of it. ::) If Code::Blocks would display all tabs as equal amounts of spaces maybe I could stand it but then there are problems when people mix tabs and spaces and use different indentation levels than I do.

Code::Blocks is especially nice for working with tabs since you can make backspace behave as if it was deleting a tab when there are spaces there and you can select blocks of text and tab them forward an indentation level or shift-tab them back an indentation level (handy when moving class source code from the header where I write it to the source file where it ends up and also when rearranging loops ;)).

CGamesPlay

Seriously. None of you are allowed to commit to my code base. You always use tabs, you never wrap long lines, and you always put comments directly above the code they document (with no fancy crap like surrounding stars). You do not line anything up with spaces, ever.

Edgar Reynaldo

The problem is that a lot of editors don't visually show you that you've typed a space or a tab so when people get forgetful and use spaces instead of tabs they aren't visually apparent so when that code gets viewed in a decent editor it's instantly apparent they've been mixing things and if you have a different tab size everything is screwed up.

With Code::Blocks if I read source code that has been consistently indented with only spaces , all I have to do is change my tab size and I can jump right in to editing the code without reformatting it. Of course if it has been consistently indented with only real tabs then I can just change the setting to not display tabs so I don't have to look at all the stupid arrows. Also that way each person could change their settings for the displayed tab size to their liking. The problem is like I said earlier - when people use tabs , they generally forget to be consistent because many editors don't give you visual cues and end up mixing spaces in. It's a matter of consistency is all and if I was working on a project with other people we would agree beforehand how everything should be formatted.

Peter Wang
Quote:

you never wrap long lines,

Yeah, great, then when you need to work on a different screen or you just want to have two windows side-by-side, you need to start scrolling horizontally. You can keep your write access.

Albin Engström

I hate space.. tab is the shit.

Actually I'm kind of a maniac when It comes to space.. as soon as i find an auto generated space in my dev-c++ project I tend to look thought the whole file and make sure there are no more spaces where there should be tabs. ;D

This is why i love notepad++ and hate dev-c++.

Onewing

Indentation is for making easy, readable and organized code. It's purely visual aesthetics. It seems the only problem with tabs is going from one editor to the next, which, as far as I'm concerned, shouldn't happen enough to outweigh my desire to use tabs.

I don't even know what the argument is.

Carrus85

Personally, since it is a pain to intermix the two, I'd rather use spaces for everything and tell the developers to use the tab <-> space conversion on any decent editor to indent quickly. This has the advantage of ensuring the code layout appears the same on all fixed-width layouts, and has the additional bonus of being able to use the tab key to create columns (since they insert spaces and don't look all screwed up on different tab stop widths). This also allows you to set a meaningful maximum line length as well.

Of course, this means that you need to have a code standard so that the automatic tab insertion works off of whatever indentation scheme (2, 4, 8, 2 then 4, etc.) you're working with. But you should have a coding standard anyway, so hopefully this isn't an issue.

And just as a point of discussion, using tabs or spaces may not be that important in most cases, but if your language is whitespace significant (*cough* python cough), it can result in programs that will mysteriously fail to even run.

The point is, consistency is key; if you're going to use tabs for indentation, always use tabs for indentation (and ensure everyone who ever touches your code base does the same thing). Same argument for spaces. Mixing tabs/spaces, however, is just asking for pain. (Unless you're using tabs for the left indent, and spaces to create columns, which works; have fun hitting the space bar 80 million times though).

OICW

I would be for tab indentation since it's crystal clear and you can set a tab size to whatever size you want. However I think that I've set-up my editors to use two spaces instead of a tab character, because I was unable to track down tab size. But hey, at least I'm using one style of indentation.

ixilom

I stopped reading the tabs vs spaces replies after someone said something about sucking it up. I agree.

Just use whatever the majority uses and stop bitching. Unless its like, "We like to torture bunnies in the toilet during lunch".

SiegeLord
Quote:

Seriously. None of you are allowed to commit to my code base. You always use tabs, you never wrap long lines, and you always put comments directly above the code they document (with no fancy crap like surrounding stars). You do not line anything up with spaces, ever.

I'm up for a coding style change soon, and I am definitely switching to that. An added advantage of this, is that most of the newer editors will allow you to fold comments that are located on separate lines, which helps clear up the code especially if the comment-to-code ratio is above 5... Unfortunately it only works consistently with C style comments, but that is for another topic.

Quote:

Yeah, great, then when you need to work on a different screen or you just want to have two windows side-by-side, you need to start scrolling horizontally. You can keep your write access.

Turn on wordwrap. ;) Manually breaking lines disadvantages people with 1600 pixel wide monitors. Or avoid using long lines altogether, those are generally indicative of something else being wrong: too nested a function, too verbose a function name, too large a tab size etc.

Quote:

This has the advantage of ensuring the code layout appears the same on all fixed-width layouts.

Yes, it looks the same on all fixed-width layouts. I.e. it (potentially) looks equally bad on all fixed width layouts.

In the end, I'd suggest picking a single, simple and consistent style for yourself/your group and sticking to it. If you need to interact with other people's code, do it via some automatic styling program/plugin like astyle. It isn't perfect, but if the styles are not too esoteric, this method will work best imho. I'm using tabs for my own use until someone with a gun comes and forces me change from that, but I understand other people's sensibilities too... so I replace my tabs with 4 spaces whenever I post my code on a.cc as a compromise.

CGamesPlay
Quote:

Turn on wordwrap. ;)

Yep. And with the trend of all monitors going widescreen these days, you're just wasting space. KWrite does a sweet job of wrapping lines:

{"name":"595268","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/3\/734fc7b080d49354dbafa6e0d96be0ac.png","w":873,"h":435,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/3\/734fc7b080d49354dbafa6e0d96be0ac"}595268

Matthew Leverton

Wordwrap is evil.

Christopher Bludau
Quote:

One of the problems with tabs is that a tab character needs to be converted into whitespace by the editor when displaying the file. How much whitespace should each tab character be replaced with? In an ideal world, the old typewriter functionality could be used, where each tabstop had a certain pixel position. That way people could even use proportional width fonts in their editors (instead of the blocky monospace fonts used by practically all code editors today), and the code would still indent nicely. However, no editor that I'm aware of supports this, so that's not a practical venue. Instead, editors typically make an assumption that a tab is either 8 characters (common in ye old days) or 4 characters (common in Java editors today). Some editors will stick with the 8 character assumption, but support 4-character indents in Java (which is common), so when indenting to level 3, they will insert a tab, followed by 4 characters, to get a 12 character indent using an 8-character tab.

Why is this bad? Because code is viewed in more than one tool. In the presence of tabs, code often gets misaligned. Code integration e-mail diffs, code viewed in other editors, code edited by other tools which treats tabs in a different way will easily get "mangled" (e.g. start getting mixed spaces and tabs).

link

Matthew Leverton

I guess that settles it!

Vanneto

I agree, tabs win, spaces loose, close this puppy down. ;D

Thomas Fjellstrom
Quote:

link [blogs.sun.com]

As has been said, mixing spaces and tabs like that is stupid. ::) Any editor that does that is horribly broken.

Christopher Bludau
Quote:

Any editor that does that is horribly broken.

It doesn't happen because the editor is broken, but because more then one person edits one file.

As always. Having a convention is the way to go.
So if your boss says that it's done this way, then do it.
Conventions aren't always there to get the best result, but to get the same result from anyone.

We at work do have convention i don't like and I don't follow them in my private time.
But at work I do it because that results in similiar code from each developer.

OnlineCop

Wow; I read, like, 5 of the replies so far but there was too much blah-blah-blah for me to stay interested.

I like to use tabs to indent, but not to align, my code and comments. It irritates me when people use tabs as a fix-all kludge, because if I happen to like a tab to indent the equivalent of 3 spaces instead of 4 or 8, seeing someone else's code is all ugly and I either need to fix MY settings to see it "properly" or reformat THEIR code just so I can see things in the way they intended.

At work, they are 100% tabs (50% of the time, they use tabs instead of spaces between words as well, which irritates me even more). The only way I can live with it without going postal is the fact that I have several MASSIVE monitors that I don't need to scroll horizontally to see everything.

This is what I do at home, though (I'll show tabs with "--|" to indicate tab-spacing boundaries):

1#include <allegro.h>
2#include "myIncludes.h"
3 
4class something
5{
6--|public:
7--|--|something(); // Default constructor
8--|--|~something(); // Default destructor
9 
10--|--|unsigned int size(); // Return the size of the array
11--|--|char *getString(); // Return a pointer to the string
12--|--|void setString(char *); // Set the string
13 
14--|private:
15--|--|char *mString; // Private array for the strings
16--|--|unsigned int mSize; // Size of the string
17};
18 
19// ...and so on, and so forth...
20 
21int someFunction(int aaa, char *bbb, bool flag = false)
22{
23--|// First, we're going to do something with 'aaa',
24--|// then something else with "bbb", and finally, check
25--|// whether or not "flag" is set to TRUE. If it's not,
26--|// life as we know is must end and all people must die.
27 
28--|// ... stuff ...
29 
30--|int reallyLongVariable = someScope::ID_TRUST_ME; // Notice where the indentation
31--| // is on this line, and that I pad with a
32--| // single TAB, and then fill the rest with
33--| // spaces to ALIGN.
34 
35}

So as the example shows, no matter WHAT my tab settings may be, all the comments (especially those hanging comments near the bottom) will be aligned: your tab settings may be at 1 character, or 8, or 4,8,12,20,24,32 for all I care: it all lines up in the end.

So I like to indent with tabs, but after I followed the previous line's indentation (so if it has a couple tabs, I match those tabs), I use spaces to actually align everything up to look nice and orderly.

Sorry if someone already answered this above, and I just didn't feel like reading your posts/comments. :P

Evert
Quote:

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?

To paraphrase, yes, this is that sort of thing: if they tell you to use spaces for their programming style, you use spaces. If they tell you to use tabs, you use tabs.

I find the whole argument increadibly silly. It's like C vs C++, Windows vs Linux, Vim vs emacs, Allegro vs SDL. You can bitch and argue and rationalise about all of those as much as you want, in the end of the day it's personal preference which you prefer. That said, if you work on a project with multiple contributors, you follow the coding style set for that project. It is much more important to follow a consistent style than to follow the style you're most used to.

As to my personal preferences, I used to use tabs but nowadays I use spaces. I think Peter's post gives a neat summary as to why. A lot of the programming I do on a day-to-day basis involves legacy FORTRAN code, which you're not officially allowed to indent with tabs to begin with (and lines start with six space indents). Some compilers let you anyway, but some don't.
As to the "pressing tab once is better than pressing space several times" I've seen come up again, get a real editor. You know, one that can be configured to insert spaces when you press tab and can treat multiple spaces as one tab.

OnlineCop
Evert said:

It's like C vs C++, Windows vs Linux vs Mac, Vim vs emacs vs cat and sed, Allegro vs SDL vs ASM

Fixed ;D

Karadoc ~~

OnlineCop, in what sense is "It's like vs C++, vs vs Mac, vs vs cat and sed, vs vs ASM" 'fixed'?

Secondly, I found this kind of funny.

Quote:

Wow; I read, like, 5 of the replies so far but there was too much blah-blah-blah for me to stay interested. [followed by a large post]

If you lost interest as you said, what motivated you to post that! :p

Thomas Fjellstrom
Quote:

As to the "pressing tab once is better than pressing space several times" I've seen come up again, get a real editor. You know, one that can be configured to insert spaces when you press tab and can treat multiple spaces as one tab.

I must have skipped that post.. My particular argument deals with navigating through space indented code with the arrow keys, its extreamly annoying and my arthritis and/or RSI starts to flare up by all the extra repetitive key presses (1 vs. 3, 4, or 8).

And before you tell me to "get a real editor" fuck you vi and emacs suck ass. Their key shortcuts alone add to the repetitive key pressing cough*M^c-buckyball-crap-butterfly:qw*cough. If you can't make an editor simpler people, get out of the software business, k thanks. (kate works perfectly well for me)

Christopher Bludau

ctrl + left or right will get you to the next word (in nearly any editor on win or linux, don't know for mac)
so it doesn't matter if you skip 4 spaces or 2 tabs.
Because with one press you are where you want to be.

So to be as rude as this thread has been so far, I could say that this argument is the same bullshit as the rest.

Thomas Fjellstrom
Quote:

So to be as rude as this thread has been so far, I could say that this argument is the same bullshit as the rest.

I don't want to skip ALL of the tabs all of the time ::) just one, or two maybe.

Christopher Bludau
Quote:

I don't want to skip ALL of the tabs all of the time ::) just one, or two maybe.

the sense behind that stays hidden...

Matthew Leverton

It's funny because the argument of "get a real editor that treats spaces as tabs" could easily be changed to "get a real [email client | diff generator] that understands tabs." It really is a personal preference, but obviously if you like spaces then you are wrong.

CGamesPlay

I just found out that Kate support vim-style modelines, so you can configure the indent setting on a per-file basis. Handy to know :)

Evert
Quote:

My particular argument deals with navigating through space indented code with the arrow keys, its extreamly annoying and my arthritis and/or RSI starts to flare up by all the extra repetitive key presses (1 vs. 3, 4, or 8).

Fair enough. That said, I actually need to press fewer keys in VIM than I ever had to using another editor, but I appreciate that in getting to that point one has to pass through a stage with many more keypresses than necessary.

Quote:

It's funny because the argument of "get a real editor that treats spaces as tabs"[...]

For the record and clarity, that's not what I said.

Thomas Fjellstrom
Quote:

Fair enough. That said, I actually need to press fewer keys in VIM than I ever had to using another editor, but I appreciate that in getting to that point one has to pass through a stage with many more keypresses than necessary.

The fact that KDE sets up a "Default Editor" component (kpart), and that a VIM kpart happens to exist means I might try it out in the future (it lets the Kate editor and KDevelop actually use Vim inside as the editor widget). But last time I tried Vim it was quite unfriendly. I've been in Linux land for almost 10 years now, and it took me most of that time to find out how to just save and exit in vim :P (:wq). The first couple times I was ever in vi/vim, I tried the fancy embedded tutorial and docs, and they didnt help one bit. I had to switch to another vty to kill vim.

Evert
Quote:

But last time I tried Vim it was quite unfriendly.

It's not, actually, once you know and understand the logic behind the commands. That said, the learning curve is very very steep, especially in the beginning.

Quote:

I've been in Linux land for almost 10 years now, and it took me most of that time to find out how to just save and exit in vim :P (:wq).

We had a UNIX course that included basic vi in the first trimester in the first year when I came to university, which basically covered how to enter and leave insert mode, and how to quit. Not much, but enough to make you not have to kill vi from another terminal because you don't know how to exit from it.
Not that I used it (vim, that is) much until about half a year or so ago.

Quote:

The first couple times I was ever in vi/vim, I tried the fancy embedded tutorial and docs, and they didnt help one bit. I had to switch to another vty to kill vim.

Never tried that, actually. I probably should, since I feel I'm missing some essential background when I'm trying to read the vim documentation. Anyway, {"name":"vi-vim-cheat-sheet.gif","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/8\/f856948618747708157b5ad689e0ba04.gif","w":1024,"h":724,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/8\/f856948618747708157b5ad689e0ba04"}vi-vim-cheat-sheet.gif is a very useful thing to print and have handy when you're learning to use vi. http://jmcpherson.org/editing.html is a useful link as well.
That said, learn vim if you want to and/or have a reason to (I wanted an editor that had native versions for both X11 and OS X and wasn't called emacs), but why bother if you're happy with the editor you have? :)

Matthew Leverton

Do you have a VI keyboard overlay too? ;D

Evert

You know, I'd love one of those keyboards with LED lights on each key and have it change the enscription on the keys depending on whether I'm insert mode or normal mode.
Not worth the money though, besides, I'm willing to bet it doesn't come with VIM keybindings.

OICW

No, but you can program it. Not sure if it would work under Linux, because I got used to the fact that Linux sucks in hardware support, which isn't its own fault.

Jakub Wasilewski
Quote:

[The VI keys image] is a very useful thing to print and have handy when you're learning to use vi

I like the exclamation mark after "not used" on the backslash. It's as if the author of the chart was shocked by the fact that there is a key without a command bound to it in vi :).

Thread #596280. Printed from Allegro.cc