| |||
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 |
Kernal |
| ||
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 |
| ||
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 |
| ||
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 |
| ||
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 |
| |||
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 |
|
Xeon |
| ||
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 |
| ||
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 |
| ||
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 |
| ||
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 Either just braces or curly braces.
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 |
| ||
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 |
| ||
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 |
| ||
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 |
| ||
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 I write my code the same way. D: But I'm never consistent with brace placement. ____________________ |
Drag |
| ||
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 That's pretty much exactly how I feel. Thanks for putting it in better words. ____________________ |
DarkSlaya |
| ||
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 |
| ||
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 |
| ||
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:
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 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 |
| ||
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 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 |
| ||
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(){ 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 KernalBecause 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 |
| ||
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:
|
Main - Computing - Programming Poll #5: { } | New thread | New reply |
© 2005-2023 Acmlm, blackhole89, Xkeeper et al. |
MySQL - queries: 102, rows: 130/131, time: 0.019 seconds. |