Points of Required Attention™
Please chime in on a proposed restructuring of the ROM hacking sections.
Views: 88,495,953
Main | FAQ | Uploader | IRC chat | Radio | Memberlist | Active users | Latest posts | Calendar | Stats | Online users | Search 04-28-24 09:58 AM
Guest: Register | Login

0 users currently in Computing | 1 guest

Main - Computing - Programming Poll #1: Indent Style New thread | Thread closed

Pages: 1 2

Kernal
Posted on 02-26-07 02:11 PM Link | Quote | ID: 7885

Gone
Level: 88

Posts: 136/1881
EXP: 6463200
Next: 187464

Since: 02-20-07

Last post: 6148 days
Last view: 6139 days
Yes, I know there's no poll feature, just give your answer in the thread.

Question #1 is: How many spaces do you indent your code, and do you use tabs or spaces?

I like to indent each block by 4 spaces. The default tab stop of 8 is just way too much for me, it causes the blocks to be really spread out horizontally in my opinion and you quickly run out of space for more blocks, especially when you have like a switch inside an if-else inside a loop inside another loop. One or two spaces doesn't set off the block enough for me. I prefer spaces to tabs becase I want it to show up as 4 spaces everywhere, whereas when I use tabs, loading the file in a different editor will show me eight spaces. I know tabs use less space in the file, but that doesn't matter too much in these days of multigigabyte hard drives.

blackhole89
Posted on 02-26-07 06:09 PM Link | Quote | ID: 7941


The Guardian
Moloch whose eyes are a thousand blind windows!
Level: 124

Posts: 63/4196
EXP: 21536306
Next: 300295

Since: 02-19-07
From: Ithaca, NY, US

Last post: 473 days
Last view: 86 days



I use the default tab. It's 4 characters wide in MS Visual Studio (and I actually prefer it that way), but even in 8 character defaulting editors like vi, I use it out of plain laziness.

For this board, it's 2 spaces though because that's Acmlm's style and the code would look like crap if everybody involved used a different indentation style.

____________________



setz
Posted on 02-26-07 06:21 PM Link | Quote | ID: 7946


Spike
fuck~
Level: 58

Posts: 48/722
EXP: 1537140
Next: 40406

Since: 02-19-07
From: Pittsburgh, PA

Last post: 5292 days
Last view: 2580 days
I just use the tab key, because it just makes it easy to keep your code lined up, and its 3 less keypresses than jamming on the spacebar 4+ times. I've always used tabs over spaces, though. spaces just seemed like a waste of time.

____________________

Acmlm
Posted on 02-26-07 06:31 PM Link | Quote | ID: 7947


Flurry
Level: 37

Posts: 36/251
EXP: 315085
Next: 23168

Since: 02-19-07
From: Mirabel, Québec, Canada

Last post: 6182 days
Last view: 1815 days




Flurry
#&postrank&
Like blackhole said, 2 spaces for me, at least for here (I still use Tab, there's an option in EditPlus to make it enter spaces) But I've also worked with 4-space tabs at times ...

AcmlmBoard 1.x was another story, where I used 2 space indents but grouped them into 6-space tabs to save space ... don't do that

____________________

Randy53215
Posted on 02-26-07 06:33 PM Link | Quote | ID: 7948


Shyguy
Banned by request
Level: 22

Posts: 19/81
EXP: 57761
Next: 589

Since: 02-19-07
From: Greenfield, Wisconsin (U.S.A)

Last post: 6093 days
Last view: 6071 days
Posted by Acmlm
Like blackhole said, 2 spaces for me, at least for here (I still use Tab, there's an option in EditPlus to make it enter spaces) But I've also worked with 4-space tabs at times ...


Essentially how I do things, depending how "big" the project is. I try to keep things as clean as possible.

And YAY for a computer forum.

Drag
Posted on 02-26-07 06:38 PM Link | Quote | ID: 7951


Spike
Dragon
Level: 57

Posts: 86/705
EXP: 1483205
Next: 2723

Since: 02-19-07
From:

Last post: 3930 days
Last view: 3930 days
I use all sorts of different kinds of indentations (mostly because the different editors I use handle tabs differently. )

I use tabs most often, because it's really easy... press tab, yay indent! Press backspace, yay unindent! I'd rather there be too much instead of not enough.

In NetBeans, I also use tabs, but NetBeans usually treats that like I've pressed space 4 times, so if I don't have the cursor in the right place when I hit tab, it'll indent incorrectly, leaving extra spaces or something. Also, to unindent, I have to backspace four times. Kind of a pain.

____________________

xeno
Posted on 02-26-07 07:34 PM Link | Quote | ID: 7971


Micro-Goomba
Level: 9

Posts: 7/10
EXP: 2505
Next: 657

Since: 02-21-07
From: Somewhere around here...

Last post: 6204 days
Last view: 6103 days
I just always tab. It's easiest and doesn't require me to think about indenting.

yup...

Dr. Sophie
Posted on 02-26-07 08:00 PM Link | Quote | ID: 7979


Goomba
Level: 12

Posts: 16/21
EXP: 7625
Next: 296

Since: 02-19-07

Last post: 6145 days
Last view: 6078 days
Two quick jams on the spacebar do it for me.
When I started coding things, I didn't like tab for spacing (for some reason I forgot), and instead used spaces.

An indention with only one space looked too small, an indention with 3 and upwards spaces looked too big for me. So I used 2, and I just got used to that.

Kawa
Posted on 02-26-07 08:22 PM Link | Quote | ID: 7985


CHIKKN NI A BAAZZKIT!!!
80's Cheerilee is best pony
Level: 138

Posts: 47/5344
EXP: 30949704
Next: 713277

Since: 02-20-07
From: The Netherlands

Last post: 4500 days
Last view: 2635 days
I do it like
foo

{
bar
} else
{
baz
}
, me...

____________________
Wife make lunch - Shampoo
Opera - give it a spin
Spare some of your free time?
<GreyMaria> I walked around the Lake so many goddamn times that my sex drive was brutally murdered
Kawa rocks — byuu

Randy53215
Posted on 02-26-07 08:49 PM Link | Quote | ID: 7990


Shyguy
Banned by request
Level: 22

Posts: 20/81
EXP: 57761
Next: 589

Since: 02-19-07
From: Greenfield, Wisconsin (U.S.A)

Last post: 6093 days
Last view: 6071 days
Mine look something like...


if (!$_GET['module'])

{

$location = 'Home';

}

else

{

$location = 'Not Home';

}

Katelyn
Posted on 02-26-07 09:09 PM Link | Quote | ID: 7995

beh
Level: 86

Posts: 217/1816
EXP: 6130859
Next: 11248

Since: 02-21-07

Last post: 6148 days
Last view: 6148 days
I usually use two spaces for indents while coding in PHP and C++.

OoBurns
Posted on 02-26-07 09:23 PM Link | Quote | ID: 8000


Boo
Level: 68

Posts: 155/1036
EXP: 2641981
Next: 86819

Since: 02-19-07
From: It is a mystery.

Last post: 5724 days
Last view: 5724 days
I use the default tab, no matter whether I just using Notepad or a separate program. I find it's easier to keep organized when I just press tab rather than a certain number of spaces.

____________________

blackhole89
Posted on 02-26-07 09:25 PM Link | Quote | ID: 8001


The Guardian
Moloch whose eyes are a thousand blind windows!
Level: 124

Posts: 67/4196
EXP: 21536306
Next: 300295

Since: 02-19-07
From: Ithaca, NY, US

Last post: 473 days
Last view: 86 days



    do {
        fread(&r,2,1,fl);
        if(r!=0 && r!=0x00FF && r!=0xFF00)
        {
            // ++ Anzahl der Pattern im Song
            songs[my_spcblock.nsongs].patternptrs=(unsigned short*)realloc(songs[my_spcblock.nsongs].patternptrs,2*(songs[my_spcblock.nsongs].npatterns+1));
            songs[my_spcblock.nsongs].patternptrs[songs[my_spcblock.nsongs].npatterns]=fileio_loadpattern(fl,r+delta,delta);
            
            // ++ Anzahl der Gesamtpattern, falls neues geladen
            if(songs[my_spcblock.nsongs].patternptrs[songs[my_spcblock.nsongs].npatterns] == npatterns) ++npatterns;
            // ++ Anzahl der Pattern im Song
            ++songs[my_spcblock.nsongs].npatterns;
        } else if(r==0xFF) {
        {
            fread(&r,2,1,fl);
            songs[my_spcblock.nsongs].nLoop=((r+delta)-sloc)/2; //# of loopback pattern
            r=0xFF;
        }
    } while(r!=0 && r!=0x00FF && r!=0xFF00 && r!=0xFFFF && r>(sloc-delta));

From Solar Soundtrack's code. Gives a pretty good idea of my general formatting style. (Yes, changing back and forth between German and English comments all the time is part of it)

____________________



Kernal
Posted on 02-26-07 10:20 PM Link | Quote | ID: 8025

Gone
Level: 88

Posts: 144/1881
EXP: 6463200
Next: 187464

Since: 02-20-07

Last post: 6148 days
Last view: 6139 days
Not to mention alternating between Allman and K&R style of positioning the curly brackets (which will probably be Programming Poll #2).

blackhole89
Posted on 02-26-07 10:25 PM Link | Quote | ID: 8029


The Guardian
Moloch whose eyes are a thousand blind windows!
Level: 124

Posts: 71/4196
EXP: 21536306
Next: 300295

Since: 02-19-07
From: Ithaca, NY, US

Last post: 473 days
Last view: 86 days



Disregard the doubled curly after the else if statement, I apparently copied it by accident when reformatting the code to display right in HTML.
It's just
...
} else if(r==0xFF) {
fread...

But yeah, I never paid much attention to the curly placing.
void function(int lol)
{
stuff
},
void function(int lol) {
stuff
}
and void function(int lol) {stuff} all are fine to me.

____________________



HydraPheetz
Posted on 02-26-07 10:25 PM Link | Quote | ID: 8030


Red Cheep-cheep
Level: 34

Posts: 22/216
EXP: 251534
Next: 2117

Since: 02-19-07

Last post: 6089 days
Last view: 6070 days
I tend to do this with my code (at least with languages that employ non-whitespace/non-newline statement terminators):


if (a != 0) {
bar();
} else {
foo();
}


I only use tabs. I just use a tabstop of 8 (default in vim) and I split my lines where necessary (in languages like Python, where I can, especially for typing out long strings and passing a list of variables to be formatted in a string) so I don't get have to scroll around too much.

____________________
Justus League

THIS SIGNATURE IS SPAMMY ACCORIDNG TO BLACKHOLE89

Cellar Dweller
Posted on 02-26-07 11:36 PM Link | Quote | ID: 8046


Snifit
Level: 39

Posts: 2/287
EXP: 385247
Next: 19524

Since: 02-19-07
From: Arkansas

Last post: 4054 days
Last view: 3221 days
I use the K&R bracing style (aka The One True Bracing Style) with a four space indent. I have my editor configured to use spaces for tabs.

The following is a code sample that I appear to have stopped in the middle of coding some time ago.


int decode_recr(struct decode_state *ds, char *wp)
{
uint64_t cmd;
GBI_MATERAL_NODE *matp;
GBI_TRIANGLE_NODE *trip;
// GBI_VERTEX_NODE *verp[3];
int i;

for (;;) {
if (wp < ds->buf || (wp+8) > ds->buf_end) {
printf("wp has gone out of bounds in decode_recr()\n");
return 0;
}
cmd = rbeu64(wp);
//printf("%02x ", (int)(*wp));
wp+=8;
printf("%08x : %016llx %02x\n", ((int)(wp-ds->buf)), cmd, GBI_EX_CMD(cmd));

switch (GBI_EX_CMD(cmd)) {
case F3D_NOOP:
break;

case F3D_VTX:
if (ds->seg != (exfld64(cmd, 24, 8))) {
printf("vertex reference to other segment\n");
return 0;
} else {
int i;
int j;
char *vwp;
char *vwp_end;

i = exfld64(cmd, 52, 4); /* number of vertices -1 */
j = exfld64(cmd, 48, 4); /* where to load */
if ((i+1)*16 != exfld64(cmd, 32, 16)) {
printf("vertex command not consistant with self\n");
return 0;
}
if (i+j > 0x0f) {
printf("vertex command would overflow vertex cache\n");
return 0;
}
vwp = ds->buf + exfld64(cmd,0,24);
vwp_end = vwp + (i+1)*16;
if (vwp_end > ds->buf_end) {
printf("vertex command points past end of segment\n");
return 0;
}
while (vwp < vwp_end) {
ds->vertex_cache[j].pt[0] = rbes16(vwp);
ds->vertex_cache[j].pt[1] = rbes16(vwp+2);
ds->vertex_cache[j].pt[2] = rbes16(vwp+4);
/*todo: support colors and normals*/
ds->vertex_cache[j].tc[0] = rbes16(vwp+8);
ds->vertex_cache[j].tc[1] = rbes16(vwp+10);
vwp+=16;
j++;
}
}
break;

case F3D_DL:
if (ds->seg != exfld64(cmd, 24, 8)) {
printf("Ignoring external DL at this time.\n");
} else {
if (!(decode_recr(ds, ds->buf+exfld64(cmd, 0, 24)))) {
return 0;
}
}
break;

case F3D_ENDDL:
return 1;

case F3D_TRI1:
/*Search materals until a match is found*/
matp = ds->lg->mat_head;
while (matp && !(ds->curr_mat.is_same_as(matp))) {
matp = matp->next;
}
if (!matp) {
GBI_MATERAL_NODE *matq;

matq = new GBI_MATERAL_NODE;
if (!matq) {
printf("out of memory\n");
return 0;
}

*matq = ds->curr_mat;
matq->next = ds->lg->mat_head;
ds->lg->mat_head = matq;
matp = matq;
}

trip = new GBI_TRIANGLE_NODE;
if (!trip) {
printf("out of memory\n");
return 0;
}

for (i=0; i<3; i++) {
GBI_VERTEX_NODE *srchpat;
/* search vertices until a match is found */
srchpat = &(ds->vertex_cache[exfld64(cmd, 8*(2-i), 8)/10]);
trip->v[i] = ds->lg->vertex_head;
while (trip->v[i] && !(srchpat->is_same_as(trip->v[i]))) {
trip->v[i] = trip->v[i]->next;
}
/* if no matching vertex is found, create a new one */
if (!trip->v[i]) {
GBI_VERTEX_NODE *nvn;

nvn = new GBI_VERTEX_NODE;
if (!nvn) {
printf("out of memory\n");
}
*nvn = *srchpat;
nvn->next = ds->lg->vertex_head;
ds->lg->vertex_head = nvn;
trip->v[i] = nvn;
}
}
/* triangle complete! join the other triangles! */
trip->next = matp->triangles;
matp->triangles = trip;
break; /*phew!*/

case RDP_RDPLOADSYNC:
break;

case RDP_SETTILE:


case RDP_SETTIMG: /* 0xfd - 11111101 fffss... ....wwww wwwwwwww pppppppp pppppppp pppppppp pppppppp*/
ds->curr_mat.tex.img.pixelformat = exfld64(cmd, 53, 3);
ds->curr_mat.tex.img.pixelsize = exfld64(cmd, 51, 2);
ds->curr_mat.tex.img.width = exfld64(cmd, 32, 12);
ds->curr_mat.tex.img.segptr = exfld64(cmd, 0, 32);
ds->curr_mat.tex.img_defined = 1;
break;

default:
printf("unknown GBI command %x\n", (int)(GBI_EX_CMD(cmd)));
}
}
}


never-obsolete
Posted on 02-27-07 12:15 AM Link | Quote | ID: 8064


Rat
Level: 24

Posts: 2/96
EXP: 74507
Next: 3618

Since: 02-22-07
From: Phoenix, AZ

Last post: 2598 days
Last view: 2598 days
I use 3 space tabs for high level languages, and 20 space tabs for assembly.

spiroth10
Posted on 02-27-07 04:40 AM Link | Quote | ID: 8218


Paratroopa
Level: 29

Posts: 27/143
EXP: 135457
Next: 12428

Since: 02-22-07

Last post: 5917 days
Last view: 5915 days
My code looks like:

int main(){
//code goes here
if(2+2 == 4){
printf("mooraidians rocks\n");
}
else {
//more code
}
//even more code
return 0;
}

although I couldn't use tab for formatting, so I had to guess using only the spacebar .

HydraPheetz
Posted on 02-27-07 04:47 AM Link | Quote | ID: 8223


Red Cheep-cheep
Level: 34

Posts: 23/216
EXP: 251534
Next: 2117

Since: 02-19-07

Last post: 6089 days
Last view: 6070 days
Posted by spiroth10
My code looks like:

int main(){
//code goes here
if(2+2 == 4){
printf("mooraidians rocks\n");
}
else {
//more code
}
//even more code
return 0;
}

although I couldn't use tab for formatting, so I had to guess using only the spacebar .

It wouldn't show up correctly using just spaces. :<
Stick it inside some <code> tags:


<pre><code>Hello, world!</code></pre>


____________________
Justus League

THIS SIGNATURE IS SPAMMY ACCORIDNG TO BLACKHOLE89
Pages: 1 2


Main - Computing - Programming Poll #1: Indent Style New thread | Thread closed

Acmlmboard 2.1+4δ (2023-01-15)
© 2005-2023 Acmlm, blackhole89, Xkeeper et al.

Page rendered in 0.036 seconds. (321KB of memory used)
MySQL - queries: 92, rows: 120/121, time: 0.018 seconds.