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)
Matthew Leverton
Supreme Loser
January 1999
avatar

I prefer:

                 void output(ostream &out)
                                         {
           for(int i = 0; i < 24; i++)
                          if(i%24)
    for(int j = 0; j < i; j++)
     out << i * j << endl;
                                         }

bamccaig
Member #7,536
July 2006
avatar

I prefer:

                                         }
     ;ldne << j * i << tuo
    )++j ;i < j ;0 = j tni(rof
                          )42%i(fi
           )++i ;42 < i ;0 = i tni(rof
                                         {
                      )tuo& maertso(tuptuo

The compiler hates me. :'(

Neil Black
Member #7,867
October 2006
avatar

public
static
void
main(String
args[]){
System.out.println("Hello
World");
}

My style of choice is a bit unorthodox.

CGamesPlay
Member #2,559
July 2002
avatar

int _main_loop_ = _tick<_while<_not<keys<KEY_ESC> >,_compound<_while<_gt<timer, _const<0> >,_compound< dec_timer,_compound<_compound<_compound<_if<_and<keys<p1_up>, _gt<_get<p1>, _get<top> > >, _addeq<p1, _neg<_const<1> > >, _if<_and<keys<p1_dn>, _lt<_add<_get<p1>, _const<paddle_h> >, _get<bottom> > >, _addeq<p1, _const<1> >, _nil> >, _if<_and<keys<p2_up>, _gt<_get<p2>, _get<top> > >, _addeq<p2, _neg<_const<1> > >, _if<_and<keys<p2_dn>, _lt<_add<_get<p2>, _const<paddle_h> >, _get<bottom> > >, _addeq<p2, _const<1> >, _nil> > >, _compound<_compound< _addeq<bx, _get<bxv> >, _addeq<by, _get<byv> > >, _if<_lt<_get<by>, _get<top> >, _compound<_set<by, _get<top> >, _set<byv, _const<1> > >, _if<_gt<_get<by>, _get<bottom> >, _compound<_set<by, _add<_get<bottom>, _const<-1> > >, _set<byv, _const<-1> > >, _nil> > > >, _compound<_if<_and<_lt<_get<bx>, _add<_add<_get<left>, _const<paddle_w> >, _const<ball_r> > >, _and<_not<_lt<_get<by>, _get<p1> > >, _not<_gt<_get<by>, _add<_get<p1>, _const<paddle_h> > > > > >, _set<bxv, _const<1> >, _if<_and<_gt<_get<bx>, _add<_add<_get<right>, _const<-paddle_w> >, _const<-ball_r> > >, _and<_not<_lt<_get<by>, _get<p2> > >, _not<_gt<_get<by>, _add<_get<p2>, _const<paddle_h> > > > > >, _set<bxv, _const<-1> >, _nil> >, _if<_lt<_get<bx>, _get<left> >, _compound<_compound<_set<bx, _const<paddle_w> >, _set<by, _add<_get<p1>, _const<paddle_h / 2> > > >, _compound<_set<bxv, _const<1> >, _addeq<s2, _const<1> > > >, _if<_gt<_get<bx>, _get<right> >, _compound<_compound<_set<bx, _add<_get<right>, _const<-paddle_w> > >, _set<by, _add<_get<p2>, _const<paddle_h / 2> > > >, _compound<_set<bxv, _const<-1> >, _addeq<s1, _const<1> > > >, _nil > > > > > >, _compound<_compound<draw<score<_get<s1>, _get<s2> > >, draw<ball<_get<bx>, _get<by> > > >, _compound<_compound<draw<paddle<_get<left>, _get<p1> > >, draw<paddle<_add<_get<right>, _neg<_const<paddle_w> > >, _get<p2> > > >, draw<flip> > > > > >(); // This line is 1984 characters long at this dot.

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

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

BAF
Member #2,981
December 2002
avatar

How did I know that was coming!

ReyBrujo
Moderator
January 2001
avatar

Yeah :)

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

OICW
Member #4,069
November 2003
avatar

Quote:

How did I know that was coming!

;D Maybe because it was here before and this is a.cc? 8-)

[My website][CppReference][Pixelate][Allegators worldwide][Who's online]
"Final Fantasy XIV, I feel that anything I could say will be repeating myself, so I'm just gonna express my feelings with a strangled noise from the back of my throat. Graaarghhhh..." - Yahtzee
"Uhm... this is a.cc. Did you honestly think this thread WOULDN'T be derailed and ruined?" - BAF
"You can discuss it, you can dislike it, you can disagree with it, but that's all what you can do with it"

Trezker
Member #1,739
December 2001
avatar

Comments go before the code it describes, not on the same line.
There, no problems with aligning. Aligning always breaks every time you edit the code anyway so if anything is evil, it's comments behind code.

CGamesPlay
Member #2,559
July 2002
avatar

Oh, since this thread is still around, I want to highlight the experience I had with Dev-Cpp the other day. I needed to use that because it was the best available source code editor on a particular system.

1void my_function();
2 
3int main(int argc, char* argv[])
4{
5 /* notice the 4 space indent */
6 my_function();
7}
8 
9void my_function()
10{
11 /* hmm, 5 space indent... that's... weird */
12 for(int x = 0; x < SCREEN_W; x++)
13 {
14 /* 13 space indent, wait what? */
15 int y = 0;
16 while(getpixel(screen, x, y) == makecol(255, 255, 255))
17 {
18 /* uhmmmmmmm */
19 count++;
20 } /* no surprise, but dev-cpp doesn't un-indent the closing brace either */
21 }
22}

In other words, Dev-Cpp indents with 8-width tabs plus spaces a number of times equal to the index of the first space character in the previous line plus one ::) If you try to remove the idiotic scheme it's got, you can backspace to where you need to be and then hit tab to automatically reapply the idiotic indentation scheme ::)

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

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

Dustin Dettmer
Member #3,935
October 2003
avatar

Yeah it sucks but there's a setting for it. The one thing Dev-Cpp is really missing is highlighting multiple lines and hitting tab or shift-tab.

BAF
Member #2,981
December 2002
avatar

X-Code does that too. I lose a whole block of code, and have to hit undo, and the whole time I'm thinking to myself "why would I ever want to replace a whole block of code with a tab?"

Karadoc ~~
Member #2,749
September 2002
avatar

I use 4 spaces (not tab, spaces; is that "hard" or "soft" spaces?). When I'm posting code on a.cc I use just 2 spaces. I prefer to use spaces rather than tabs because they are more predictable. A space is always just a space on any computer in any (sane) editor, but tabs vary in size. (Disclaimer: I'm not trying to say that spaces are better than tabs or anything like that. I know there are many good reasons for using tabs. I'm just giving the main reason for my preference.)

-----------

CGamesPlay
Member #2,559
July 2002
avatar

Quote:

A space is always just a space on any computer in any (sane) editor, but tabs vary in size.

A tab is always a tab: exactly how big I want it to be, regardless of whose code I'm reading.

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

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

Karadoc ~~
Member #2,749
September 2002
avatar

CGamesPlay said:

A tab is always a tab: exactly how big I want it to be, regardless of whose code I'm reading.

Wow. I'd never thought of that before. I'm completely converted! :P

-----------

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Quote:

A tab is always a tab: exactly how big I want it to be,

If your editor supports resizing tabs, and if you don't mind having to change your tab size setting every time you want to read someone else's code, invariably due to 'tab + space' indentation. :-/

CGamesPlay
Member #2,559
July 2002
avatar

Quote:

If your editor supports resizing tabs, and if you don't mind having to change your tab size setting every time you want to read someone else's code, invariably due to 'tab + space' indentation. :-/

The only place that happens is in legacy Allegro source code, which was 3 space indentation with 8-space tabs used when possible. Seriously wtf.

Anyways, what you're saying is a lie. Anybody whose code I've read is tab indentation with space alignment and it works properly, every time.

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

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

OnlineCop
Member #7,919
October 2006
avatar

Edgar Reynaldo said:

If your editor supports resizing tabs, and if you don't mind having to change your tab size setting every time you want to read someone else's code, invariably due to 'tab + space' indentation. :-/

Which wouldn't be a problem if everyone used tabs to indent, and spaces to align...

Some a.cc programmers here set their tabs to be equivalent to a single space, others to 8. As long as comments are indented with tabs to the same level as the lines before/after, and then spaces to align everything, there'd be no difference in different IDEs rendering the code (except for how far horizontally you have to scroll to see too-long lines).

Of course, with monitors being wider than they are tall in most setups, word wrap set to 80 characters is outdated for most except terminal connections.

MiquelFire
Member #3,110
January 2003
avatar

Assuming the person used tab for indentation only, and no alignment what so ever. (That is, there's no place that is 8 (or whatever the editor is set to) spaces long that got replaced with a tab by the editor.

---
Febreze (and other air fresheners actually) is just below perfumes/colognes, and that's just below dead skunks in terms of smells that offend my nose.
MiquelFire.red | +Me
If anyone is of the opinion that there is no systemic racism in America, they're either blind, stupid, or racist too. ~Edgar Reynaldo

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Quote:

Anyways, what you're saying is a lie. Anybody whose code I've read is tab indentation with space alignment and it works properly, every time.

I said 'tab + space' indentation, not alignment. There was no lie, you're incorrect.

Quote:

The only place that happens is in legacy Allegro source code, which was 3 space indentation with 8-space tabs used when possible. Seriously wtf.

Which is a decent percentage of the current A4 code.

Ctrl-R for the win.

SiegeLord
Member #7,827
October 2006
avatar

Quote:

Ctrl-R for the win

AStyle for the win, since it also fixed the incorrect bracket styles as well as doing proper indentation.

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

Matthew Leverton
Supreme Loser
January 1999
avatar

The Allegro problem is because of the three space rule. Most Windows IDEs automatically impose a tab indentation style because that's what the advanced world uses. 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. Why impose your tab size on other people? >:(

Working on the Allegro codebase with space indentation makes me angry inside. >:(

And the terrible mix of tabs and spaces I accidentally commit makes the space-aholics angry inside. >:(

The other thing that makes me angry inside is opening curly braces at the end of the line. I'll never get used to doing that when working on Allegro code. And that makes the unaligned-curly-aholics angry inside. >:(

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Quote:

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.

Ah, but pressing tab once in Code Blocks lets you put a set number of spaces down in it's place if you wish it to. Which is infinitely preferable to seeing all those flipping tab arrows. Yes, you can turn off the tab arrow display as SiegeLord pointed out to me, but then you don't get to see the dotted space indicators.

Get the Code Blocks guys to implement the option to display tabs as a set of dotted spaces, and I'll quit being annoyed at all the !@#$%@# tabs.

Matthew Leverton
Supreme Loser
January 1999
avatar

Whitespace should be invisible. >:(

OnlineCop
Member #7,919
October 2006
avatar

There should be a language where whitespace is replaced by punctuation. Tabs are actually #s and spaces are actually .s.

#if.(.whitespace_is_bad.).{
##return.waffle;
#}.else.{
##return.crouton;
#}
#//This.is.a.comment.where.anything,.including     spaces     is.allowed!
#//And,.this.is.properly.indented.and.aligned!

bamccaig
Member #7,536
July 2006
avatar

Notepad++ lets you view all characters. :) It's kind of fun to see whitespace. At the same time, I think it could get in the way during real work... I usually have that feature disabled.



Go to: