Angband.oook.cz
Angband.oook.cz
AboutVariantsLadderForumCompetitionComicScreenshotsFunniesLinks

Go Back   Angband Forums > Angband > Vanilla

Reply
 
Thread Tools Display Modes
Old December 20, 2007, 20:23   #1
Bandobras
Knight
 
Join Date: Apr 2007
Posts: 726
Bandobras is on a distinguished road
Coding standard? Indentation?

I keep making a mess of indentation whenever I touch a C file from Angband, so I wonder what I should set up my Emacs to (or Eclipse, or 'indent' utility). I see a year ago I had the following conversation on the NPP forum, but now that V is again active I wonder if there are any opinions...

> > > Merry Christmas!
> > >
> > > wonder what coding standards do you adhere to.
> > > E.g. GNU (http://www.gnu.org/prep/standards/standards.html)? Any other?
> > >
> > > Also, I wonder what indentation you use: GNU, K&R? Spaces or tabs for indents?
> > > 4-wide or 8-wide tabs? What was the original standard of Moria?
> > > Of Ben Harrison's Vanillia? Do you ever use
> > > the indent utility to maintain a single format?
> > >
> > > BTW, is NPP os a CVS/SVN somewhere?
> > >
> > > Thanks a lot!
> >
> > CJN: AFAIK, most *bands, including NPP, use K&R style with 8-wide tabs and tab for indent.
> >
>
> Bad, bad, bad. But at least the tab width is standard ---
> however the text must go off 80 characters wide terminal very often...
> Hmm, from the look of the code it's not pure K&R. Obviously not GNU, too.
> I guess everybody indents as he likes...
Bandobras is offline   Reply With Quote
Old December 21, 2007, 01:51   #2
takkaria
Veteran
 
takkaria's Avatar
 
Join Date: Apr 2007
Posts: 1,947
Donated: $40
takkaria is on a distinguished road
Quote:
Originally Posted by Bandobras View Post
I keep making a mess of indentation whenever I touch a C file from Angband, so I wonder what I should set up my Emacs to (or Eclipse, or 'indent' utility). I see a year ago I had the following conversation on the NPP forum, but now that V is again active I wonder if there are any opinions...
http://rephial.org/wiki/CodingGuidelines
takkaria is offline   Reply With Quote
Old December 21, 2007, 23:45   #3
Bandobras
Knight
 
Join Date: Apr 2007
Posts: 726
Bandobras is on a distinguished road
A very nice article. It says

Quote:
Use the BSD/Allman style, and indent using tabs. Avoid lines over 80 character long (though this is not strict).
Is it 80 characters with 8 characters wide tab? That's a very wide tab...

Supposedly (Wikipedia)

Code:
indent somefile.c -st -bad --blank-lines-after-procedures -bli0 -i4 -l79 \
-ncs -npcs -nut -npsl -fca -lc79 -fc1
indents code by BSD/Allman. I wonder how much of V would fit in 80 lines if run through with that utility and with 8-characters tab.

Emacs can be set up for BSD/Allman probably just with

Code:
'(c-default-style (quote ((c-mode . "bsd") (c++-mode . "bsd"))))
'(c-basic-offset 3)
'(standard-indent 3)
'(tab-width 3)
I'll try and see if I'm less destructive with that setting.

Edit: more emacs code

Last edited by Bandobras; December 22, 2007 at 01:56.
Bandobras is offline   Reply With Quote
Old December 22, 2007, 00:02   #4
takkaria
Veteran
 
takkaria's Avatar
 
Join Date: Apr 2007
Posts: 1,947
Donated: $40
takkaria is on a distinguished road
Quote:
Originally Posted by Bandobras View Post
Is it 80 characters with 8 characters wide tab? That's a very wide tab...
8 characters would be crazy. I generally use 3, just because everyone else uses even numbers -- in this way, I can see spaces-instead-of-tabs really easily.

Quote:
Supposedly

Code:
indent somefile.c -st -bad --blank-lines-after-procedures -bli0 -i4 -l79 \
-ncs -npcs -nut -npsl -fca -lc79 -fc1
indents code by BSD/Allman. I wonder how much of V would fit in 80 lines if run through with that utility and with 8-characters tab.
Indent always manages to screw up the source. Steven Fuerst (previous Z developer) wrote a patch for indent that makes it indent code Angband-style.
takkaria is offline   Reply With Quote
Old December 25, 2007, 21:56   #5
pav
Administrator
 
pav's Avatar
 
Join Date: Apr 2007
Location: Prague, Czech republic
Age: 41
Posts: 790
pav is on a distinguished road
Send a message via ICQ to pav
Tabs are ment to be eight spaces wide That's the end of it.
That said, it does not matter much on a 300+ columns terminal.
__________________
See the elves and everything! http://angband.oook.cz
pav is offline   Reply With Quote
Old December 25, 2007, 22:04   #6
Bandobras
Knight
 
Join Date: Apr 2007
Posts: 726
Bandobras is on a distinguished road
Those wide-screen monitors?
Bandobras is offline   Reply With Quote
Old December 25, 2007, 22:13   #7
pav
Administrator
 
pav's Avatar
 
Join Date: Apr 2007
Location: Prague, Czech republic
Age: 41
Posts: 790
pav is on a distinguished road
Send a message via ICQ to pav
Quote:
Originally Posted by Bandobras View Post
Those wide-screen monitors?
Pretty wide. Good for coding, bad for scrollback.
__________________
See the elves and everything! http://angband.oook.cz
pav is offline   Reply With Quote
Old March 22, 2008, 00:48   #8
Bandobras
Knight
 
Join Date: Apr 2007
Posts: 726
Bandobras is on a distinguished road
Quote:
Originally Posted by takkaria View Post
8 characters would be crazy. I generally use 3, just because everyone else uses even numbers -- in this way, I can see spaces-instead-of-tabs really easily.
So, I now use 3 spaces wide tab, too. But I recently encountered a case where tab width matters. (This is how my emacs formats it by itself.)

Code:
 int v = MY_CONST * (wieeerd_struct->loooooooooooong_field
                     + wieeerd_struct->longeeeeeeeeeeeeeeeeeer_field
                     - wieeerd_struct->medium_field)
It's obviously tab width-depenent, so what am I doing wrong? Does it agree with BSD/Allman?

P.S. A simpler example:

Code:
 int v = (wieeerd_struct->loooooooooooong_field
          + wieeerd_struct->longeeeeeeeeeeeeeeeeeer_field
          - wieeerd_struct->medium_field)

Last edited by Bandobras; March 22, 2008 at 00:54.
Bandobras is offline   Reply With Quote
Old March 22, 2008, 00:59   #9
takkaria
Veteran
 
takkaria's Avatar
 
Join Date: Apr 2007
Posts: 1,947
Donated: $40
takkaria is on a distinguished road
Quote:
Originally Posted by Bandobras View Post
So, I now use 3 spaces wide tab, too. But I recently encountered a case where tab width matters. (This is how my emacs formats it by itself.)

Code:
 int v = MY_CONST * (wieeerd_struct->loooooooooooong_field
                     + wieeerd_struct->longeeeeeeeeeeeeeeeeeer_field
                     - wieeerd_struct->medium_field)
It's obviously tab width-depenent, so what am I doing wrong? Does it agree with BSD/Allman?

P.S. A simpler example:

Code:
 int v = (wieeerd_struct->loooooooooooong_field
          + wieeerd_struct->longeeeeeeeeeeeeeeeeeer_field
          - wieeerd_struct->medium_field)
You use tabs to indent to the same as the line you're continuing on from, and then spaces after that. This solves indentation issues with all setups.
takkaria is offline   Reply With Quote
Old March 22, 2008, 01:13   #10
Bandobras
Knight
 
Join Date: Apr 2007
Posts: 726
Bandobras is on a distinguished road
Quote:
Originally Posted by takkaria View Post
You use tabs to indent to the same as the line you're continuing on from, and then spaces after that. This solves indentation issues with all setups.
Ha, so this is emacs fault --- it does not let me mix tabs and spaces with default settings. Instead it fits as many tabs as it can and then a few spaces. Of course it's configurable, for sure...
Bandobras is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:01.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.