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

0 users currently in Computing | 1 guest

Main - Computing - Programming Poll #5: { } New thread | New reply

Pages: 1 2

Kernal
Posted on 03-14-07 02:36 AM (rev. 3 of 03-14-07 02:37 AM) Link | Quote | ID: 14895

Gone
Level: 88

Posts: 633/1881
EXP: 6458555
Next: 192109

Since: 02-20-07

Last post: 6139 days
Last view: 6130 days
A large number of programming languages, including C, C++, Java, and PHP, use the { and } symbols to enclose blocks of code. The questions that are part of Poll #5 are:

1. What do you call these symbols?

2. Where do you position them in relation to the rest of the code? For example:
void function1()
{
     doSomething();
}
vs.
void function2() {
     doSomethingElse();
}
etc.

3. If a block has only one statement in it, do you include them?

I refer to { and } as curly brackets. The word "braces" sounds really weird to me and makes me think of dental fixtures.

My preferred method of placing the curly brackets is as in the first example above (Allman style). I find it clearer and easier to read, and the lack of symmetry in the second choice (K&R style) drives me nuts.

I tend to be lazy and omit the curly brackets when there is only one statement, but when I do, I always out the one statement indented on the following line rather than just at the end of the same line. So I do:
if (os == WINDOWS)
     crash();
and not:
if (os == WINDOWS) crash();
or:
if (os == WINDOWS)
{
     crash();
}

Drag
Posted on 03-14-07 02:49 AM (rev. 2 of 03-14-07 04:22 PM) Link | Quote | ID: 14900


Spike
Dragon
Level: 57

Posts: 164/705
EXP: 1482139
Next: 3789

Since: 02-19-07
From:

Last post: 3921 days
Last view: 3921 days
I call them braces. Like, open brace, close brace. That way, (paranthesis), [brackets], and {braces} all have different names.

I do it the second way:
void blah() {
[tab] yay;
}

for 3, I usually don't include the braces if there's only one statement. However, sometimes I'll need to add another statement, and I sometimes forget to add the braces. Other times, I don't forget. Later, if I need to remove the statements and go back to just one again, I'll leave the braces in.

____________________

Ninetales
Posted on 03-14-07 02:56 AM Link | Quote | ID: 14901


Panser
Level: 42

Posts: 120/338
EXP: 492008
Next: 29354

Since: 02-19-07

Last post: 5504 days
Last view: 4902 days
Typically my code looks like this:

if (condition) {
statement;
}
else {
statement;
}


Sometimes I vary from this pattern, but this is how the majority of my code is organized.

Xkeeper
Posted on 03-14-07 02:56 AM Link | Quote | ID: 14902


Level: 105

Posts: 832/2846
EXP: 12021476
Next: 240784

Since: 02-19-07

Last post: 6053 days
Last view: 2790 days
function shit($shit) {
if ($shit != "shit") {
$shit = "shit";
}
return $shit;
}


____________________
I dealt with it.

OoBurns
Posted on 03-14-07 03:18 AM Link | Quote | ID: 14905


Boo
Level: 68

Posts: 277/1036
EXP: 2640082
Next: 88718

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

Last post: 5715 days
Last view: 5715 days
1. Curly braces, or just braces. I always think of [] when I say brackets.

2.
void Awesome()
{
booUrns.status = "awesome";
system.out.print("BooUrns is " + booUrns.status;
}

3. I include them on one-line statements, just because it helps me keep organized.

____________________

Xeon
Posted on 03-14-07 03:25 AM Link | Quote | ID: 14906


Red Paratroopa
Level: 31

Posts: 32/174
EXP: 181471
Next: 3892

Since: 03-09-07

Last post: 6013 days
Last view: 3215 days
I don't really call them anything, and I like to keep them on separate lines instead of having them on the same line as an if() statement or loops, etc.

interdpth
Posted on 03-14-07 03:26 AM Link | Quote | ID: 14908


Buzzy Beetle
Level: 44

Posts: 19/383
EXP: 593332
Next: 17953

Since: 02-22-07

Last post: 4092 days
Last view: 4065 days
if(!a) Dothis();

Or

if(!a) {
Func1();
}
else{
Func2();
}

or

if(a <> 0) then
Func1
else
func2
end if

____________________
lawl blog

http://interdpths.blogspot.com/

Spikeman
Posted on 03-14-07 10:36 AM Link | Quote | ID: 15006


Red Koopa
Pathetic excuse for a hacker
Level: 28

Posts: 47/132
EXP: 120076
Next: 11262

Since: 02-19-07

Last post: 6217 days
Last view: 6216 days
1. I call them "curly braces" or "curly brackets".

2.

if(cando) {
do();
} else {
dontdo();
}

3.

if(cando) do();

setz
Posted on 03-14-07 02:29 PM Link | Quote | ID: 15021


Spike
fuck~
Level: 58

Posts: 160/722
EXP: 1536036
Next: 41510

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

Last post: 5283 days
Last view: 2571 days
Posted by Kernal
1. What do you call these symbols?

Either just braces or curly braces.


2. Where do you position them in relation to the rest of the code?

if a function only has one statement, I go with
void function1() { dosomething(); } //this does something

if it has more than one statement
void function1()
{
doSomething(); //do this one thing
doSomethingelse(); //do this other thing
} //etc


I just find things easier to navigate when braces are all properly aligned.

____________________

Black Lord
Posted on 03-14-07 03:39 PM Link | Quote | ID: 15027


Red Cheep-cheep
Level: 35

Posts: 18/220
EXP: 258351
Next: 21585

Since: 02-19-07

Last post: 5414 days
Last view: 5414 days
They are called "braces" and I use the West-Coast/Allman style... although I could see myself using the GNU style someday.

The number of people using K&R/East-Coast style sicken me, as I literally find the style a pain in the ass to read through.

____________________


Drag
Posted on 03-14-07 04:41 PM Link | Quote | ID: 15037


Spike
Dragon
Level: 57

Posts: 167/705
EXP: 1482139
Next: 3789

Since: 02-19-07
From:

Last post: 3921 days
Last view: 3921 days
What the hell?
Why do so many people on the internet hate K&R style? I've even come across a class curriculum which specifically states that the allman style of braces are to be used, and that anything else is penalized. Penalizing for something as trivial as BRACE PLACEMENT?? I think the class should be more concerned about the actual CODE, because once that's compiled, brace placement doesn't mean a thing.

So yeah, a lot of people hate K&R style for some reason. A lot of people say it's "bad". It looks perfectly fine to me. If anything, the Allman style creates problems for me when I'm reading it, because it tends to space out lines too far for me. If I wasn't able to indent, then sure I'd use it, but indentation gives away the fact that I put an open brace there. All I need to see is how far I've indented something, and automatically, I know how many open braces (including the 'implied' ones) I have. So I save lines that way.

So anyway, I don't know why so many people absolutely despise it and cringe to look at it.

Also, apparently there's two variants of K&R:
if (blah) {
[tab] stuff;
}
else {
[tab] more stuff;
}

And the "worse" version:
if (blah) {
[tab] stuff;
} else {
[tab] more stuff;
}

So apparently, I use the "worse" kind of K&R. Yeah, I shouldn't give my code out to those picky programmers who will die upon seeing my brace placement, onoez!

Sorry if I sound a little harsh, but the fact that there are a lot of people who absolutely *HATE* this and actively PROTEST against it really sounds strange to me.

Hell, the next thing I know, people will start saying the "good" way of writing a 4 is like this:
L|, instead of the "bad" way, which is triangle 4's like in this font, which also happens to be the way I write my 4's.

____________________

Xkeeper
Posted on 03-14-07 04:45 PM Link | Quote | ID: 15041


Level: 105

Posts: 838/2846
EXP: 12021476
Next: 240784

Since: 02-19-07

Last post: 6053 days
Last view: 2790 days
Braces are, for me, unimportant; indentation and line usage means much more.

Example:

} else {

I see the "}" and relaize that it's an "else", since I never put anything else there.

Much like a line with just "{" serves to make me dislike it, because it's a wasted line. The indented code itself should tell you that you're in a code block.

____________________
I dealt with it.

HydraPheetz
Posted on 03-14-07 04:50 PM Link | Quote | ID: 15044


Red Cheep-cheep
Level: 34

Posts: 29/216
EXP: 251353
Next: 2298

Since: 02-19-07

Last post: 6080 days
Last view: 6061 days
Posted by Drag

And the "worse" version:
if (blah) {
[tab] stuff;
} else {
[tab] more stuff;
}



I write my code the same way. D: But I'm never consistent with brace placement.

____________________
Justus League

THIS SIGNATURE IS SPAMMY ACCORIDNG TO BLACKHOLE89

Drag
Posted on 03-14-07 05:13 PM Link | Quote | ID: 15048


Spike
Dragon
Level: 57

Posts: 168/705
EXP: 1482139
Next: 3789

Since: 02-19-07
From:

Last post: 3921 days
Last view: 3921 days
Posted by Xkeeper
Braces are, for me, unimportant; indentation and line usage means much more.

Example:

} else {

I see the "}" and relaize that it's an "else", since I never put anything else there.

Much like a line with just "{" serves to make me dislike it, because it's a wasted line. The indented code itself should tell you that you're in a code block.


That's pretty much exactly how I feel. Thanks for putting it in better words.

____________________

DarkSlaya
Posted on 03-14-07 08:39 PM Link | Quote | ID: 15075


Cheep-cheep
Level: 32

Posts: 45/189
EXP: 205724
Next: 718

Since: 02-19-07

Last post: 5994 days
Last view: 5986 days
no name really.

if($wtf = wtfcrap($lol))
{
//Do Stuff
$lol = mysql_query("SOMESTUFF");
}


comments are part of my coding style.

Kernal
Posted on 03-14-07 10:33 PM Link | Quote | ID: 15106

Gone
Level: 88

Posts: 638/1881
EXP: 6458555
Next: 192109

Since: 02-20-07

Last post: 6139 days
Last view: 6130 days
So, to you people who use K&R style, why don't you also put the closing curly bracket at the end of the last line of the block?

Jagori
Posted on 03-15-07 12:39 AM (rev. 3 of 03-15-07 12:40 AM) Link | Quote | ID: 15174


Red Goomba
Level: 16

Posts: 20/35
EXP: 16392
Next: 3864

Since: 02-20-07

Last post: 6063 days
Last view: 6061 days
If there isn't a convention in place that I'm following, I lay out my braces like this:

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


They're always present, even if they don't have to be, and they always get their own line except in the case of a do loop, where the condition goes on the same line following the closing brace.
Posted by Drag
I've even come across a class curriculum which specifically states that the allman style of braces are to be used, and that anything else is penalized. Penalizing for something as trivial as BRACE PLACEMENT?? I think the class should be more concerned about the actual CODE, because once that's compiled, brace placement doesn't mean a thing.

As much as that seems an inane thing to harp on, one thing that's important to learn in the comp sci field is how to do what's expected of you. If you're explicitly told by your boss/prof/team lead to format your code in a certain way, and voicing your concern doesn't get that changed, then you format your code in that way or you've failed to meet the requirements. If brace placement is so trivial, then what's the problem with putting them where you're asked to?

Drag
Posted on 03-15-07 06:42 AM Link | Quote | ID: 15279


Spike
Dragon
Level: 57

Posts: 169/705
EXP: 1482139
Next: 3789

Since: 02-19-07
From:

Last post: 3921 days
Last view: 3921 days
Posted by Kernal
So, to you people who use K&R style, why don't you also put the closing curly bracket at the end of the last line of the block?


If you need to delete the last function, you'd accidentally delete the closing brace, so the closing brace goes on the next line.

____________________

Ailure
Posted on 03-15-07 01:07 PM (rev. 3 of 03-15-07 01:12 PM) Link | Quote | ID: 15314

Hats
Steam Board2 group
Level: 121

Posts: 487/3965
EXP: 19767986
Next: 288710

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

Last post: 3294 days
Last view: 2045 days
1. Braces in English, Måsvingar in Swedish (which is translated as Gull-Wings, which I think is a nice name considering how the braces looks like)

2. If there's no kind of style I have to follow, I tend to write a method something like th e following:
public void example(){

if(true){
Object.hello();
}else if(false){
Object.bye();
}else{
bah();
}
}


3. Well, for things like "Continue;" and "Break;" I put it on the same line. For other statements I insert a break (or whatever you would call it now) and then code. I tend to skip using braces, it looks only more cluttered in my opinion if it's only a single line of code. However, sometimes I include braces if I plan to extend that part later even if the code in the block is a single line (or no line) for now.
Posted by Kernal
So, to you people who use K&R style, why don't you also put the closing curly bracket at the end of the last line of the block?
Because that makes it trickier to add code at the end of a block.

And I'm with XK. Indentation is more important than brace placement for me, I tend to work with editors that automatically fixes indentation for me (which is a time-saver), and I see no reason to space out braces when there's indention.

There's actually utilities out there that converts between code styles, some people use those tools when the project they are in uses a different style than they prefer.

I'm not really sure why I use K&R style though, it just winded up being that way. I guess I like it compact.

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


niteice
Posted on 03-16-07 02:11 AM Link | Quote | ID: 15570


Micro-Goomba
Level: 11

Posts: 4/17
EXP: 5548
Next: 437

Since: 02-23-07

Last post: 5920 days
Last view: 5917 days
Braces, used like so:

void func(int arg1, char *arg2)
{
if(arg1 == 5)
printf("pass\n");
if(arg2[0] == 's')
{
/* remember, this isn't python, so use braces where things are ambiguous.
otherwise, the second if will fall through to the else, not the first */
if(!strcmp(arg2, "string"))
printf("fail\n");
}
else
printf("fail more\n");
}
Pages: 1 2


Main - Computing - Programming Poll #5: { } New thread | New reply

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

Page rendered in 0.028 seconds. (321KB of memory used)
MySQL - queries: 102, rows: 130/131, time: 0.018 seconds.