Points of Required Attention™
Please chime in on a proposed restructuring of the ROM hacking sections.
Views: 88,521,768
Main | FAQ | Uploader | IRC chat | Radio | Memberlist | Active users | Latest posts | Calendar | Stats | Online users | Search 05-03-24 10:03 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

spiroth10
Posted on 02-27-07 05:02 AM Link | Quote | ID: 8236


Paratroopa
Level: 29

Posts: 28/143
EXP: 135511
Next: 12374

Since: 02-22-07

Last post: 5922 days
Last view: 5920 days
I know, but the edit feature isn't here yet...


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


The more I nest code, the deeper the indentations go... at least until a certain point (I have never reached this point yet).

Nesting becomes useful as a (very very limited) replacement for hyperthreading in some areas. Using do while loops for this is possible, although it slows down code immensely probably increases memory consumption (never checked), is less efficient, and less powerful as hyperthreading, but is still a viable option for some applications.

I've used such nesting for taking input before, and also for analyzing events.

Drag
Posted on 02-27-07 06:33 AM Link | Quote | ID: 8273


Spike
Dragon
Level: 57

Posts: 94/705
EXP: 1483796
Next: 2132

Since: 02-19-07
From:

Last post: 3935 days
Last view: 3935 days
I put my openbraces on the same line as the function that needs the openbrace.

void burp() {
}

struct burp {
};

if (burp) {
} else {
}

for (int burp = blah; burp < infinite; burp++) {
}

I always prefered that over putting the openbraces on the next line. I'm not quite sure why.

____________________

Ailure
Posted on 02-27-07 10:17 AM Link | Quote | ID: 8321

Hats
Steam Board2 group
Level: 121

Posts: 270/3965
EXP: 19790084
Next: 266612

Since: 02-19-07
From: Sweden, Skåne

Last post: 3308 days
Last view: 2059 days
I use four spaces, because that's the netbeans formatting default. Sometimes I do what Drag explain.

Sometimes I also put stuff on single line, such as.
if(true)runThisMethod();

Although I only do it if the line won't get too long.

In assembly, I just do a single tab. Heh. I rarely program in assembly though.

____________________
AIM: gamefreak1337, MSN: Emil_sim@spray.se, XMPP: ailure@xmpp.kafuka.org


MathOnNapkins
Posted on 02-27-07 12:41 PM Link | Quote | ID: 8336


Super Koopa
Level: 62

Posts: 28/842
EXP: 1936582
Next: 48104

Since: 02-19-07
From: durff

Last post: 4495 days
Last view: 4018 days
Drag: that style drives me nuts. I wonder if there's a tool out there that converts between East Coast and West Coast coding style .

____________________
Zelda Hacking Forum
hobbies: delectatio morosa

Kernal
Posted on 02-27-07 02:18 PM Link | Quote | ID: 8353

Gone
Level: 88

Posts: 154/1881
EXP: 6465776
Next: 184888

Since: 02-20-07

Last post: 6153 days
Last view: 6144 days
Yeah, when I was learning C, EVERY book I saw used Allman style:

int main()
{
printf("Hello world");
}

so I just got used to that style, and I think K&R style (with the left curly bracket at the end of the previous line but the right curly bracket on its own line) looks so...wrong. And unbalanced. I have a much harder time reading K&R-formatted code for some reason.

Also, I tend to omit the curly brackets if there's only one statement.

blackhole89
Posted on 02-27-07 02:26 PM Link | Quote | ID: 8354


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

Posts: 76/4196
EXP: 21544885
Next: 291716

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

Last post: 478 days
Last view: 91 days



For single statements, I usually do
if(foo) bar();
The only exception to that is when I need MSVC++' line-based debugger to distinguish between failure in evaluating foo and bar. In that case, I do
if(foo)
    bar();

Also, I think
{
    foo
}
else {
    bar
}
or even
{
    foo
}else{
    bar
}
is much friendlier to read than
{
    foo
}
else
{
    bar
}


____________________



Kernal
Posted on 02-27-07 02:28 PM Link | Quote | ID: 8355

Gone
Level: 88

Posts: 155/1881
EXP: 6465776
Next: 184888

Since: 02-20-07

Last post: 6153 days
Last view: 6144 days
Crap,, the indentation didn't show up even with < code > tags. I guess I need to use nbsp?

blackhole89
Posted on 02-27-07 02:36 PM Link | Quote | ID: 8356


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

Posts: 77/4196
EXP: 21544885
Next: 291716

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

Last post: 478 days
Last view: 91 days



<code> isn't a tag at all afaik. You probably meant <pre> (as in PREformatted), but that would yield doubled line breaks with Acmlmboard...

I should port my
...
tag to Acmlmboard2.

____________________



Kernal
Posted on 02-27-07 02:44 PM Link | Quote | ID: 8360

Gone
Level: 88

Posts: 157/1881
EXP: 6465776
Next: 184888

Since: 02-20-07

Last post: 6153 days
Last view: 6144 days
I don't know, < code > was mentioned in HydraPheetz's post, so I assumed it existed...

Kyargu
Posted on 02-27-07 06:55 PM Link | Quote | ID: 8402

between a rock and a hard place
Level: 26

Posts: 75/115
EXP: 97754
Next: 4521

Since: 02-19-07

Last post: 4454 days
Last view: 2332 days
Posted by Kernal
I don't know, < code > was mentioned in HydraPheetz's post, so I assumed it existed...

Google says it does.
also, see w3c

Also, I like to use 4 spaces for indent for pretty much the same reasons as the OP.

Cellar Dweller
Posted on 02-27-07 11:55 PM Link | Quote | ID: 8552


Snifit
Level: 39

Posts: 10/287
EXP: 385400
Next: 19371

Since: 02-19-07
From: Arkansas

Last post: 4059 days
Last view: 3226 days
I used <pre>, but first I replaced every newline with a <br> tag. When the board adds the <br> tags, it leaves the newlines in place, causing <pre> to double space the text. Actually, it might just be converting half of a CRLF to a <br> tag and leaving the other half.

MaxKnight
Posted on 02-27-07 11:58 PM Link | Quote | ID: 8554


Bullet Bill
Level: 50

Posts: 127/502
EXP: 891473
Next: 55844

Since: 02-20-07
From: Springfield, Ohio

Last post: 6105 days
Last view: 6082 days
Indent style? Visual Studio 2005 Professional's standard tabs.

Opening brackets? They get a line to themselves.

____________________
Complication: Video Game Titles
My current complication:
Girl's name who gets no more than 10 minutes of screen time in the actual game.

Jagori
Posted on 02-28-07 09:52 PM Link | Quote | ID: 8703


Red Goomba
Level: 16

Posts: 10/35
EXP: 16410
Next: 3846

Since: 02-20-07

Last post: 6077 days
Last view: 6075 days
GNU '2+2' style is what I'm most used to. 4 spaces for each level of indentation, with the braces halfway. Braces are always present and on their own line, even if I could get by without them. I seem to be one of about six people who do it this way.

if(x == 1)
{
do_stuff();
}
else
{
/* other stuff */
}


I'm mostly not picky about style, though. The only time I'll spend any effort to change a default indent style is if it's K&R. I just can't read that kind of code quickly, even if I wrote it.

setz
Posted on 02-28-07 10:46 PM Link | Quote | ID: 8740


Spike
fuck~
Level: 58

Posts: 54/722
EXP: 1537753
Next: 39793

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

Last post: 5297 days
Last view: 2585 days
Posted by Drag
for (int burp = blah; burp < infinite; burp++) {
}

I know alot of people do that, but I think it really hurts the readability.

for (int bitch=whore;bitch{
....//doshit
}

seems so much easier to read for me.

____________________

DarkSlaya
Posted on 02-28-07 11:51 PM Link | Quote | ID: 8810


Cheep-cheep
Level: 32

Posts: 26/189
EXP: 205954
Next: 488

Since: 02-19-07

Last post: 6008 days
Last view: 6000 days
Posted by setz
Posted by Drag
for (int burp = blah; burp < infinite; burp++) {
}

I know alot of people do that, but I think it really hurts the readability.



For some reason, I never really cared. But nowadays I do stuff on acmlmboards so I try to not code like that, so everyone can understand and stuff.

Squash Monster
Posted on 03-02-07 08:26 AM Link | Quote | ID: 9389


Buster Beetle
Level: 48

Posts: 6/469
EXP: 804895
Next: 18648

Since: 02-22-07
From: New York

Last post: 5704 days
Last view: 5703 days
The first thing I use is whatever the existing code I'm working with is using.

If it's my own stuff, and I'm using a halfway decent editor, I use whatever the tab size is.
If I'm not using a halfway decent editor, I use two spaces.

If I can actually be bothered to change the tab size of my editor, my preference depends on the language. Generally, 4 spaces is always cool with me. I prefer 2 spaces slightly above that for most languages, but when I'm doing assembly code I prefer 8 spaces.

I always do the separate line for the curly braces, even if that clashes with existing code. I will change people's existing code to do that if they try to make me debug code with the trailing brace. I cannot read trailing brace code.

____________________
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.021 seconds. (324KB of memory used)
MySQL - queries: 77, rows: 101/102, time: 0.013 seconds.