Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Indentation (4 spaces vs 8 spaces)

This thread is locked; no one can reply to it. rss feed Print
Indentation (4 spaces vs 8 spaces)
Karadoc ~~
Member #2,749
September 2002
avatar

Matthew said:

I've still never yet seen a useful argument why somebody would want to press a key three or four or eight times when you can just press tab once.

That's not what we're talking about. As Edgar pointed out, one doesn't have to press a key three of four or eight times to get that number of spaces. Edgar uses codeblocks, and that does it for him. I use gVim. With my gVim settings, pressing tab makes 4 spaces. It has auto-indentation, and ... well lets just say that it works in exactly the way that tabs would usually work except that the spacing is done using the space character rather than the tab character.

One reason to "impose your tab size on other people" is that sometimes I line up chunks of code that don't match the tab spacing. For example I might do something like this:

create_level("level 1 - warm up",   easy_ai,      unlimited_resources);
create_level("level 2 - challenge", medium_ai,    basic_resources);
create_level("level 3 - death",     difficult_ai, no_resources);

... Maybe that's not a good example, because you could still have tabs at the start and use the spaces inside the functions -- but the point is that sometimes the readability of code is damaged by changing the tab size. To be honest though, I don't really care much if other people are unhappy with the tab size in my code. If it is a shared project then we should agree on that kind of stuff before hand, but in my own code it doesn't matter. So I do what I do for my own convenience.

-----------

Matthew Leverton
Supreme Loser
January 1999
avatar

AHHH. You press TAB when you want to indent. You press space when you are lining things up. Anything else is insane. It never affects code readability.

Quote:

With my gVim settings, pressing tab makes 4 spaces

Right. Because you've configured it to do something bizarre. (I could configure my keyboard to press ZZZZ when I press $.) Instead, you could configure it to show a single tab AS 4 spaces. Then everybody wins.

Karadoc ~~
Member #2,749
September 2002
avatar

Like I said, Matthew, I have chosen my setting for my own convenience. Do you think that I haven't tried using tabs before? I prefer spaces. I've had a shot at trying to explain why. About all I can say now is this: if you don't like it, too bad.

-----------

Matthew Leverton
Supreme Loser
January 1999
avatar

It's okay. You use vim... tabs are the least of my concerns for you. :-/

Evert
Member #794
November 2000
avatar

Quote:

You press TAB when you want to indent. You press space when you are lining things up.

Meaning I would have to set up the tab key to produce tabs at the start of a line but spaces (for alignment) in the middle of a line. That's doable, I've seen configuration options that do that. Still - it wouldn't be clever enough to insert spaces when I'm aligning a continued line, so it's not good enough.

Anyway, another reason I generally prefer spaces to tabs, personally: FORTRAN doesn't allow tabs to indent.
Sorry, let me rephrase that: some FORTRAN compilers do not allow you to use tabs to appear at the beginning of a line. Others do, but that doesn't help.

That said, anyone getting overly upset about something like this needs a hobby.

Mokkan
Member #4,355
February 2004
avatar

I can see Matthew foaming at the mouth from here. :o

Matthew Leverton said:

TABS REEEE

Matthew Leverton
Supreme Loser
January 1999
avatar

Quote:

Meaning I would have to set up the tab key to produce tabs at the start of a line but spaces (for alignment) in the middle of a line.

You'd use the space bar to put spaces in the middle of the line...

I don't get it. If you wanted to align this code:

012345678901234567890123456789

struct foo {
         | press tab 6 times |
         v                v
   int x;                  // lala
   int meaning_of_life;    // lala
                       ^  ^ 
                      | press tab 2 times, then backspace 2 times
                      | or press tab 1 time and space 1 time
}

Do you ever press spacebar? Or do you use tab between words too? ;D

Evert
Member #794
November 2000
avatar

Quote:

You'd use the space bar to put spaces in the middle of the line...

Ah, see, now, I don't - I align comments at the end of a line by pressing tab (which inserts spaces). Fewer keystrokes and more convenient to hit rapidly in succession.

Quote:

| press tab 2 times, then backspace 2 times
| or press tab 1 time and space 1 time

What sort of broken editor would you use that you'd need to do that? I have tab stops set every three characters, hitting tab brings me to the next tab stop (inserting spaces).
Unless you don't line up comments on tab stops. But that would just be weird.

Matthew Leverton
Supreme Loser
January 1999
avatar

Quote:

I have tab stops set every three characters, hitting tab brings me to the next tab stop (inserting spaces).

That's different from claiming that hitting tab inserts three spaces, which is what the other tab users on this thread have been saying.

And no, I don't see any point to lining up on "tab stops." If I want to align my comments (or whatever), they'll be uniform relative to the length of the longest line in the area.

bamccaig
Member #7,536
July 2006
avatar

It would be handy to have a key combination to enter spaces instead of a tab for the times when you are aligning with spaces (you could get within the tabsize of the alignment tabsize times faster and then adjust as appropriate). I wonder what editors support such a thing... :-/

Evert
Member #794
November 2000
avatar

Quote:

And no, I don't see any point to lining up on "tab stops." If I want to align my comments (or whatever), they'll be uniform relative to the length of the longest line in the area.

In my code they're on the next tabstop after the longest line needing a comment in the same logical block - which is typically one or two spaces after the end of the line anyway.

Quote:

It would be handy to have a key combination to enter spaces instead of a tab for the times when you are aligning with spaces (you could get within the tabsize of the alignment tabsize times faster and then adjust as appropriate). I wonder what editors support such a thing...

I've seen configuration settings that do that (or similar) for vim. Also configurations for making the tab key insert tabs at the start of a line, spaces in the middle of a line (if there are non-white space characters to the left) and cleverly act as a completion key (as in the shell) while you're typing a word.

Karadoc ~~
Member #2,749
September 2002
avatar

Matthew said:

That's different from claiming that hitting tab inserts three spaces, which is what the other tab users on this thread have been saying.

The tab stop thing is what I had in mind when I said this: "It has auto-indentation, and ... well lets just say that it works in exactly the way that tabs would usually work except that the spacing is done using the space character rather than the tab character." I just didn't want to describe the details of what it does only to have someone in the next post say "tabs do that too. That's what tabs are for!"

-----------

Cody Harris
Member #4,406
March 2004
avatar

The answer, obviously, is 42.

ps: tabs, size 4.

---------------------------------
Homepage - Art (Photography)
I'm QBasicer on #allegro on Freenode.

ReyBrujo
Moderator
January 2001
avatar

Tabs don't break Python?

By the way, you need to fix your tabs if you want to write in Whitespace.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

CGamesPlay
Member #2,559
July 2002
avatar

Of course not. A soft tab width of 1 (i.e. 1 space) won't break python either, as long as you are consistent. You can even mix tabs and spaces, as long as you are consistent: if the first line of a block is indented with a string of whitespace characters (tabs, spaces, or both), all lines in that block must be indented similarly.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

decepto
Member #7,102
April 2006
avatar

Does anyone else keep there line length below 80 chars like me?

--------------------------------------------------
Boom!

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Kitty Cat
Member #2,815
October 2002
avatar

Quote:

Does anyone else keep there line length below 80 chars like me?

I try to. On (rare) occasions it's difficult or unsightly to, though, so I let it spill over sometimes.

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

I normally use tabs, with tabs set to display at 3 spaces. I find 4 is too large, and 8 is insane. But for some projects, like allegro, I try to set tab to insert spaces instead of tabs.

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

ReyBrujo
Moderator
January 2001
avatar

Still do, mostly because, from time to time, I use console/DOS. It also helps to keep the code tidy: if you got an if that has 5 or 6 expressions, there is something wrong.

My .vimrc:

colorscheme darkblue
set ts=4
set history=100
set et
set noautoindent
set nocindent
set path=/usr/include,/usr/local/include,../include,.,/usr/include/c++/4.2.1
syntax on

tabstop at 4, expand tabs into spaces (I hate the tab character), and remove both autoindentations, I like having full control.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

OnlineCop
Member #7,919
October 2006
avatar

I follow as a guideline to keep my code under 80 characters, but break that often because some code is really just too long to break neatly. I'd rather have a very long, but easily understandable, line of code than something broken at funny places just to get things within parentheses within those constraints.

But I have a lot of wide monitors also, and find that on some projects where I like to use descriptive variable (and function) names, as long as it doesn't make me scroll horizontally, it's not too long.

Evert
Member #794
November 2000
avatar

Quote:

Does anyone else keep there line length below 80 chars like me?

Normally, yes. For the same reason the standard TeX line is relatively narrow: it's easier to read if lines are not too long.
Although FORTRAN is so annoying with continuing lines that are to long that I sometimes ignore it. To continue on the next line in FORTRAN you have two options, depending on whether your dialect is F77 or F90. In F77, break the line and then insert a character in column 6 of the next line to indicate that line continues from the previous one. In F90 mode, insert an & at the end of the line you wish to break - of course these conventions are incompatible.
Naturally, I have to tell my compiler that I'm using lines that are longer than 75 characters, or it will truncate the line at that point and most likely produce an error.

bamccaig
Member #7,536
July 2006
avatar

My current, WIP, .vimrc (littered with commented lines; " is a comment character, IIRC):

:set number
:set ruler
:set tabstop=4

"set term=ansi
"set term=color_xterm
syntax on

":hi Normal
:hi comment cterm=none ctermfg=darkgreen

:hi constant cterm=none ctermfg=black
:hi identifier cterm=none ctermfg=black
:hi operator cterm=bold ctermfg=black
:hi string cterm=none ctermfg=black

:hi matchparen cterm=none ctermfg=white

:hi boolean cterm=none ctermfg=darkblue
:hi statement cterm=none ctermfg=darkblue
:hi type cterm=none ctermfg=darkblue

:hi preproc cterm=none ctermfg=darkcyan

:hi character cterm=bold ctermfg=darkgray
:hi special cterm=none ctermfg=darkgray

":hi underlined
":hi error cterm=none ctermfg=red

I configured the syntax highlighting to be more like the Visual Studio defaults I started with (i.e., keywords are blue, close to 0x0000FF, comments are dark green, numbers and strings are black, etc.). I just prefer it that way... :-/ There's probably a more correct place to put the highlighting, but oh well...

decepto said:

Does anyone else keep there line length below 80 chars like me?

I try to as well. I often work from a Linux terminal and also just find that as a rule 80 chars is a good cut off point.

Dimebagdan
Member #10,084
August 2008
avatar

I use tab's, simply because they're faster than pressing the space bar. But I've been forced to use the space more and more recently, because codeblocks didn't want to link up to allegro properly, so I had to use Dev-Cpp which seems to do wierd things when it comes to spacing.

When I'm doing DirectX though, I use MSV, which seems to be a lot more friendly about layout :). (So tabs there).

Evert
Member #794
November 2000
avatar

Quote:

I use tab's, simply because they're faster than pressing the space bar.

That's a rather silly reason; most people using spaces will press the tab key too, but just have it configured to insert spaces rather than tabs.
That's actually maybe the main the reason I use spaces rather than tabs: it's faster to align code by pressing tab than by pressing the space bar repeatedly. On the other hand, "ni <esc>" might be even faster. ;)



Go to: