What are your curly-bracing style?
-
Which method do u use for curly braces to create scope of a programming structure? I mostly prefer this method:
if(a>b)
{ // sometimes i write comment here about logic and parameters etc.
print "b is less than or equal to a"
print "it means a is greater than b"
}
else
print "a is either either equal to or less than b"Note that, I don't use braces for a single line of scope and I indent the starting brace and ending brace and it is not on the same line where the control structure is defined. I use this approach because it makes easy (just hit Enter key, no need to press Tab key) to add a new line of code after the staring brace and before the first statement of the block. I use Notepad++ and it has slightly good matching braces hilting feature and this method helps to correctly lineup and identify scope content. Here are some more methods used my many programmers:
if(a>b) { // this is Flash's ActionScript's default formatting, I hate this style the most, I feel it most unreadable, some Java programmers and web designers working on CSS also use almost similar method for writing CSS rules
print "b is less than or equal to a"
print "it means a is greater than b"
} else {
print "a is either either equal to or less than b"
}if(a>b)
{
print "b is less than or equal to a"
print "it means a is greater than b"
}
else
{
print "a is either either equal to or less than b"
}if(a>b)
{ print "b is less than or equal to a"
print "it means a is greater than b"
}I used the 1st alt method many years, but now use the 2nd alt method as it is much easier (for me) to see the block structure. I use an indent with 2 spaces per level
Steve _________________ I C(++) therefore I am
-
Which method do u use for curly braces to create scope of a programming structure? I mostly prefer this method:
if(a>b)
{ // sometimes i write comment here about logic and parameters etc.
print "b is less than or equal to a"
print "it means a is greater than b"
}
else
print "a is either either equal to or less than b"Note that, I don't use braces for a single line of scope and I indent the starting brace and ending brace and it is not on the same line where the control structure is defined. I use this approach because it makes easy (just hit Enter key, no need to press Tab key) to add a new line of code after the staring brace and before the first statement of the block. I use Notepad++ and it has slightly good matching braces hilting feature and this method helps to correctly lineup and identify scope content. Here are some more methods used my many programmers:
if(a>b) { // this is Flash's ActionScript's default formatting, I hate this style the most, I feel it most unreadable, some Java programmers and web designers working on CSS also use almost similar method for writing CSS rules
print "b is less than or equal to a"
print "it means a is greater than b"
} else {
print "a is either either equal to or less than b"
}if(a>b)
{
print "b is less than or equal to a"
print "it means a is greater than b"
}
else
{
print "a is either either equal to or less than b"
}if(a>b)
{ print "b is less than or equal to a"
print "it means a is greater than b"
}Code block is so long I can't see the voting bar! This is my preferred style:
if(a>b)
{
print "b is less than or equal to a";
print "it means a is greater than b";
}Each curly brace on it's own line, don't know why but it helps me read the code :confused:
-
Code block is so long I can't see the voting bar! This is my preferred style:
if(a>b)
{
print "b is less than or equal to a";
print "it means a is greater than b";
}Each curly brace on it's own line, don't know why but it helps me read the code :confused:
+1
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997 -
Which method do u use for curly braces to create scope of a programming structure? I mostly prefer this method:
if(a>b)
{ // sometimes i write comment here about logic and parameters etc.
print "b is less than or equal to a"
print "it means a is greater than b"
}
else
print "a is either either equal to or less than b"Note that, I don't use braces for a single line of scope and I indent the starting brace and ending brace and it is not on the same line where the control structure is defined. I use this approach because it makes easy (just hit Enter key, no need to press Tab key) to add a new line of code after the staring brace and before the first statement of the block. I use Notepad++ and it has slightly good matching braces hilting feature and this method helps to correctly lineup and identify scope content. Here are some more methods used my many programmers:
if(a>b) { // this is Flash's ActionScript's default formatting, I hate this style the most, I feel it most unreadable, some Java programmers and web designers working on CSS also use almost similar method for writing CSS rules
print "b is less than or equal to a"
print "it means a is greater than b"
} else {
print "a is either either equal to or less than b"
}if(a>b)
{
print "b is less than or equal to a"
print "it means a is greater than b"
}
else
{
print "a is either either equal to or less than b"
}if(a>b)
{ print "b is less than or equal to a"
print "it means a is greater than b"
}Aaahhh, the other developer on earth that uses this horrid style. Our main developer uses this and we never let him forget how unreadable it is.
-
Code block is so long I can't see the voting bar! This is my preferred style:
if(a>b)
{
print "b is less than or equal to a";
print "it means a is greater than b";
}Each curly brace on it's own line, don't know why but it helps me read the code :confused:
-
I'll tell you my style, but you should brace yourself first.
-
Code block is so long I can't see the voting bar! This is my preferred style:
if(a>b)
{
print "b is less than or equal to a";
print "it means a is greater than b";
}Each curly brace on it's own line, don't know why but it helps me read the code :confused:
+3 I'm a white space fanatic! :)
- S 50 cups of coffee and you know it's on! Code, follow, or get out of the way.
-
+3 I'm a white space fanatic! :)
- S 50 cups of coffee and you know it's on! Code, follow, or get out of the way.
Steve Echols wrote:
I'm a white space fanatic!
That makes you a bracist...
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997 -
Which method do u use for curly braces to create scope of a programming structure? I mostly prefer this method:
if(a>b)
{ // sometimes i write comment here about logic and parameters etc.
print "b is less than or equal to a"
print "it means a is greater than b"
}
else
print "a is either either equal to or less than b"Note that, I don't use braces for a single line of scope and I indent the starting brace and ending brace and it is not on the same line where the control structure is defined. I use this approach because it makes easy (just hit Enter key, no need to press Tab key) to add a new line of code after the staring brace and before the first statement of the block. I use Notepad++ and it has slightly good matching braces hilting feature and this method helps to correctly lineup and identify scope content. Here are some more methods used my many programmers:
if(a>b) { // this is Flash's ActionScript's default formatting, I hate this style the most, I feel it most unreadable, some Java programmers and web designers working on CSS also use almost similar method for writing CSS rules
print "b is less than or equal to a"
print "it means a is greater than b"
} else {
print "a is either either equal to or less than b"
}if(a>b)
{
print "b is less than or equal to a"
print "it means a is greater than b"
}
else
{
print "a is either either equal to or less than b"
}if(a>b)
{ print "b is less than or equal to a"
print "it means a is greater than b"
}nikunjbhatt84 wrote:
if(a>b) { // sometimes i write comment here about logic and parameters etc. print "b is less than or equal to a" print "it means a is greater than b" } else print "a is either either equal to or less than b"
That will just get you laughed at and generally ridiculed in our shop...
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997 -
Steve Echols wrote:
I'm a white space fanatic!
That makes you a bracist...
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997Nice one! :thumbsup:
- S 50 cups of coffee and you know it's on! Code, follow, or get out of the way.
-
Which method do u use for curly braces to create scope of a programming structure? I mostly prefer this method:
if(a>b)
{ // sometimes i write comment here about logic and parameters etc.
print "b is less than or equal to a"
print "it means a is greater than b"
}
else
print "a is either either equal to or less than b"Note that, I don't use braces for a single line of scope and I indent the starting brace and ending brace and it is not on the same line where the control structure is defined. I use this approach because it makes easy (just hit Enter key, no need to press Tab key) to add a new line of code after the staring brace and before the first statement of the block. I use Notepad++ and it has slightly good matching braces hilting feature and this method helps to correctly lineup and identify scope content. Here are some more methods used my many programmers:
if(a>b) { // this is Flash's ActionScript's default formatting, I hate this style the most, I feel it most unreadable, some Java programmers and web designers working on CSS also use almost similar method for writing CSS rules
print "b is less than or equal to a"
print "it means a is greater than b"
} else {
print "a is either either equal to or less than b"
}if(a>b)
{
print "b is less than or equal to a"
print "it means a is greater than b"
}
else
{
print "a is either either equal to or less than b"
}if(a>b)
{ print "b is less than or equal to a"
print "it means a is greater than b"
} -
The proper way.
if (something){ do stuff do more stuff } else{ do something different }
Am I showing my age if I mention Kernighan and Ritchie? :)
Colin Rae wrote:
Am I showing my age if I mention Kernighan and Ritchie
Yes Incidentally the C++ guy (am I showing my age if I have forgotten his name) used
if (something)
{
DoSomething();
}
else
{
DoSomethingElse();
}(not sure on the bracketed single line though)
___________________________________________ .\\axxx (That's an 'M')
-
Aaahhh, the other developer on earth that uses this horrid style. Our main developer uses this and we never let him forget how unreadable it is.
Joe Woodbury wrote:
Aaahhh, the other developer on earth that uses this horrid style
I know quite a few.
-
Colin Rae wrote:
Am I showing my age if I mention Kernighan and Ritchie
Yes Incidentally the C++ guy (am I showing my age if I have forgotten his name) used
if (something)
{
DoSomething();
}
else
{
DoSomethingElse();
}(not sure on the bracketed single line though)
___________________________________________ .\\axxx (That's an 'M')
I much prefer the opening brace on the same line as the statement it belongs to. Just seems nicer to me - I see an if or whatever and look for the corresponding closing brace below it. If I really wanted to show my age, I'd mention the fact that in first year at uni, we used DECWRITER IV hard copy terminals (for you young 'uns, that's basically a printer instead of a monitor)! After doing some course work in the evening, you'd end up going home carrying about half a tree! I missed punched cards by about 2 years - but my older brother used them!
-
I used the 1st alt method many years, but now use the 2nd alt method as it is much easier (for me) to see the block structure. I use an indent with 2 spaces per level
Steve _________________ I C(++) therefore I am
Steve Mayfield wrote:
I use an indent with 2 spaces per level
First thing I do when a new dev comes on board, change ALL your indents to 2 spaces. There is nothing worse than picking up some code with a mixture of indents.
Never underestimate the power of human stupidity RAH
-
Which method do u use for curly braces to create scope of a programming structure? I mostly prefer this method:
if(a>b)
{ // sometimes i write comment here about logic and parameters etc.
print "b is less than or equal to a"
print "it means a is greater than b"
}
else
print "a is either either equal to or less than b"Note that, I don't use braces for a single line of scope and I indent the starting brace and ending brace and it is not on the same line where the control structure is defined. I use this approach because it makes easy (just hit Enter key, no need to press Tab key) to add a new line of code after the staring brace and before the first statement of the block. I use Notepad++ and it has slightly good matching braces hilting feature and this method helps to correctly lineup and identify scope content. Here are some more methods used my many programmers:
if(a>b) { // this is Flash's ActionScript's default formatting, I hate this style the most, I feel it most unreadable, some Java programmers and web designers working on CSS also use almost similar method for writing CSS rules
print "b is less than or equal to a"
print "it means a is greater than b"
} else {
print "a is either either equal to or less than b"
}if(a>b)
{
print "b is less than or equal to a"
print "it means a is greater than b"
}
else
{
print "a is either either equal to or less than b"
}if(a>b)
{ print "b is less than or equal to a"
print "it means a is greater than b"
}My style is:
if (something)
{
DoSomething();
SoSomethingOther();
}
else
{
DoTheOpposite();
}As with every style or methodology I use, I try to have a reason for using it, so that I can justify it (even if only to myself!) and, importantly, change should a better method come along (using reasoning to define 'better') So: By having the 'if' aligned with the start and end brace, when scanning code it is trivial to visually see the structure - scan up from the end brace, you just need to look for another brace. If the start brace is at the end of a line of code, then scanning up from an end brace you need to look for if, while, do etc.etc. I always use braces, even with a single line. If, later on, I come back and need to add more cod to the If or the Else, then I insert it between the braces, and never forget - so I don't re-engineer
if (a==b)
printf("a is equal to b");to
if (a==b)
printf("a is equal to b");
HandleCasesWhereaEqualsb();With the advent of cleverer editors, with automatic indenting, highlighting of code blocks etc., the reasoniong becomes somewhat less important - but you don't get all of that when you open source in or print it (does anyone still print code?) And with the cost of VS2010 in the thousands, I can't guarantee that the editor of my choice will be on every workstation I need to edit on. Some of your reasoning is valid (in my view) but I always think that this obsession some programmers have with the reduction in keystrokes (I'd have to press TAB all the time to indent, I don't want to type two extra braces if I don't need to etc.) is plain silly. Much more time is spent looking at code than writing it - often looking for a problem, more often looking for divine intervention or, at least, inspiration!
___________________________________________ .\\axxx (That's an 'M')
-
I much prefer the opening brace on the same line as the statement it belongs to. Just seems nicer to me - I see an if or whatever and look for the corresponding closing brace below it. If I really wanted to show my age, I'd mention the fact that in first year at uni, we used DECWRITER IV hard copy terminals (for you young 'uns, that's basically a printer instead of a monitor)! After doing some course work in the evening, you'd end up going home carrying about half a tree! I missed punched cards by about 2 years - but my older brother used them!
Colin Rae wrote:
I missed punched cards by about 2 years
Baby! I was a guru on the Holorith manual punch card machine! Hard copy terminals? We dreamed of hard copy terminals (first one we had was a T.I. one with thermal paper which, being a smoker back in the day, used to get really annoying when browsing a listing with a fag (English!) in my hand! And re the braces - see my post elsewhere, but your case only deals with finding the if then searching for the end brace - what about finding the end brace and searching up for the - oh, could be an If or some sort of loop, start of a class, method etc. etc.
___________________________________________ .\\axxx (That's an 'M')
-
Steve Mayfield wrote:
I use an indent with 2 spaces per level
First thing I do when a new dev comes on board, change ALL your indents to 2 spaces. There is nothing worse than picking up some code with a mixture of indents.
Never underestimate the power of human stupidity RAH
-
Code block is so long I can't see the voting bar! This is my preferred style:
if(a>b)
{
print "b is less than or equal to a";
print "it means a is greater than b";
}Each curly brace on it's own line, don't know why but it helps me read the code :confused:
Mine too. :thumbsup:
-
Colin Rae wrote:
I missed punched cards by about 2 years
Baby! I was a guru on the Holorith manual punch card machine! Hard copy terminals? We dreamed of hard copy terminals (first one we had was a T.I. one with thermal paper which, being a smoker back in the day, used to get really annoying when browsing a listing with a fag (English!) in my hand! And re the braces - see my post elsewhere, but your case only deals with finding the if then searching for the end brace - what about finding the end brace and searching up for the - oh, could be an If or some sort of loop, start of a class, method etc. etc.
___________________________________________ .\\axxx (That's an 'M')