Points of Required Attention™
Please chime in on a proposed restructuring of the ROM hacking sections.
Views: 88,545,199
Main | FAQ | Uploader | IRC chat | Radio | Memberlist | Active users | Latest posts | Calendar | Stats | Online users | Search 05-06-24 08:01 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: 6467276
Next: 183388

Since: 02-20-07

Last post: 6156 days
Last view: 6147 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: 1484140
Next: 1788

Since: 02-19-07
From:

Last post: 3938 days
Last view: 3938 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: 492673
Next: 28689

Since: 02-19-07

Last post: 5521 days
Last view: 4919 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: 12037705
Next: 224555

Since: 02-19-07

Last post: 6070 days
Last view: 2807 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: 2643646
Next: 85154

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

Last post: 5732 days
Last view: 5732 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: 181717
Next: 3646

Since: 03-09-07

Last post: 6030 days
Last view: 3232 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: 594133
Next: 17152

Since: 02-22-07

Last post: 4109 days
Last view: 4082 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: 120238
Next: 11100

Since: 02-19-07

Last post: 6234 days
Last view: 6233 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: 1538109
Next: 39437

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

Last post: 5300 days
Last view: 2587 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: 258700
Next: 21236

Since: 02-19-07

Last post: 5431 days
Last view: 5431 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: 1484140
Next: 1788

Since: 02-19-07
From:

Last post: 3938 days
Last view: 3938 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: 12037705
Next: 224555

Since: 02-19-07

Last post: 6070 days
Last view: 2807 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: 251692
Next: 1959

Since: 02-19-07

Last post: 6096 days
Last view: 6078 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: 1484140
Next: 1788

Since: 02-19-07
From:

Last post: 3938 days
Last view: 3938 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: 206002
Next: 440

Since: 02-19-07

Last post: 6011 days
Last view: 6003 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: 6467276
Next: 183388

Since: 02-20-07

Last post: 6156 days
Last view: 6147 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: 16414
Next: 3842

Since: 02-20-07

Last post: 6080 days
Last view: 6078 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: 1484140
Next: 1788

Since: 02-19-07
From:

Last post: 3938 days
Last view: 3938 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: 19794674
Next: 262022

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

Last post: 3311 days
Last view: 2062 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: 5555
Next: 430

Since: 02-23-07

Last post: 5937 days
Last view: 5934 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.030 seconds. (322KB of memory used)
MySQL - queries: 102, rows: 130/131, time: 0.019 seconds.