Coding standards: curly bracket style
-
Yeah - I hate reading 1TB because it does it's damnedest to hide the open bracket. I'm not fond of Allman either - I use Whitesmiths as it just feels more "together" to indent the brackets to the same level as the code block it's enclosing:
if (a == b)
{
c();
}Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
I guess it depends on whether you consider the brackets part of the enclosing code block or the enclosed code block.
Wrong is evil and must be defeated. - Jeff Ello
-
Vark111 wrote:
Javascript - Style 2. To the point that if I see javascript written in Style 1, I don't even recognize it as valid javascript.
Good call. The javascript engine's semicolon injector behaves in ways that make it clear it doesn't regard opening braces on the next line as valid js either. It will "helpfully" turn this:
//I want to do stuff 10 times
for (int i = 0; i < 10; i++)
{
DoStuff()
}... into this:
//I want to do stuff 10 times
for (int i = 0; i < 10; i++); //Javascript engines thoughts: Do nothing loop. This makes no sense unless the programer is an idiot, but he wrote javascript so that's a reasonable assumption.
{
DoStuff(); //Javascript engines thoughts: not part of a loop body, will execute only once
}:doh: :doh: :doh: :doh:
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt
Dan Neely wrote:
The javascript engine's semicolon injector behaves in ways that make it clear it doesn't regard opening braces on the next line as valid js either.
Yeah, I really wish there was a way to turn off ASI in my js files (like a 'use strict' kind of thing).
-
There Are 10 Types Of Programmers[^] Mediation[^] Made me laugh! :laugh:
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
Well - when it comes right down to it,
struct doneRight Melody_Crawford_Cleaned_Up_Their_Mess() {
"Their indents sucked";
} // struct doneRight Melody_Crawford_Cleaned_Up_Their_Mess()
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein
"If you are searching for perfection in others, then you seek disappointment. If you are seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010
-
Here we go.... :) On a more serious note, I've seen both coding styles, and I despise #2. It just makes the code harder to read - *to me*. Am I just an old fart? I read an actual flaming rant about CamelCase (this is not) vs. camelCase (camels have humps in the middle). So, I finally get that. But the curlies? jumping into fox hole now.
Charlie Gilley Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
I think on the one of the Microsoft Guide lines for Capitalisation they call it PascalCasing instead of CamelCasing and then use camelCase also.
-
...weepy widdle Richard :laugh:
-
There Are 10 Types Of Programmers[^] Mediation[^] Made me laugh! :laugh:
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
My 2¢: I was a devotee of K&R braces (the second style) for a long time. When I started programming in C#, I switched to Allman[^] braces (the first style). I've grown to prefer Allman to an extent such that I've written a VS editor macro to reformat K&R braces to Allman. I don't use the built-in VS reformatting; they screw up too many other things.
Software Zen:
delete this;
-
In the absence of an established corporate coding standard, when editing an existing file, you should always adapt the style already used in the file. When creating a new file, you are free to go your own way, but consideration should be given to maintaining the same style as the other files in the folder (if there is a dominant style). When I'm at home, I use the first style. At work, I'm lucky enough to working on my own stuff, so my preferred style is in force there as well.
".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
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013During my first year as a CompSci student, I got hold of a 'large' program: The 'Open Source' Pascal compiler, written in itself (yes, open source did exist before Linux! What Linux did was introducing the term) from ETH. In those days, a Pascal program couldn't be broken into modules: Everything had to be put into a single source file, even if it was a 20-30 kloc compiler. This compiler source code was very consistent in the coding style of the tokenizer and parser. It was also very consistent in the semantic analysis. And it was highly consistent in the code generating functions. Three quite different, but very consistent coding styles, within a single source file. Even today I am surprised that they managed to keep it that way, without messing up each other's coding style. (I assume that there must have been three guys resposible for one part each.)
-
There Are 10 Types Of Programmers[^] Mediation[^] Made me laugh! :laugh:
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
-
There Are 10 Types Of Programmers[^] Mediation[^] Made me laugh! :laugh:
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
One of the good things about Visual Studio is that if one of my colleagues have been making changes to the product I am responsible for, and ignored the bracing / indentation rules, I just delete and reinsert the final closing brace of the file, and everyting is back to the 'proper' style. Oh well, the end-of-line-comments may not be properly lined up, in the parts that were changed, but that's not a terribly big problem (besides, most programmers use end-of-line comments very sparingly). ("My" product is a C# thing. I have noticed that VS is not as good with C++ as it is with C#, and I don't know if this works the same way in C++.)
-
I guess it depends on whether you consider the brackets part of the enclosing code block or the enclosed code block.
Wrong is evil and must be defeated. - Jeff Ello
This! :thumbsup: Stroustrup K&R is what I learned, and seems more logical to me (and easier on my eyes). Brackets separate a block of code that is performed as part of a command, so to my mind the opening bracket belongs on the same line as the command.
if (true) {
DoThis();
}VB adopts K&R in its own way. Note the keywords and closing keywords:
If True Then
DoThis()
End IfBut now I've probably hurt my case. :laugh: (edited to clarify the Stroustrup version of K&R)
If you think 'goto' is evil, try writing an Assembly program without JMP.
-
One of the good things about Visual Studio is that if one of my colleagues have been making changes to the product I am responsible for, and ignored the bracing / indentation rules, I just delete and reinsert the final closing brace of the file, and everyting is back to the 'proper' style. Oh well, the end-of-line-comments may not be properly lined up, in the parts that were changed, but that's not a terribly big problem (besides, most programmers use end-of-line comments very sparingly). ("My" product is a C# thing. I have noticed that VS is not as good with C++ as it is with C#, and I don't know if this works the same way in C++.)
Or just type CTRL+K then D - it'll reformat it without an edit being needed.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
-
Here we go.... :) On a more serious note, I've seen both coding styles, and I despise #2. It just makes the code harder to read - *to me*. Am I just an old fart? I read an actual flaming rant about CamelCase (this is not) vs. camelCase (camels have humps in the middle). So, I finally get that. But the curlies? jumping into fox hole now.
Charlie Gilley Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Yes you are an old fart, who cares what other people source looks like... Using a decent editor (even the Visual Studio editor does this): just go to the last close curly delete it, then put it back (or just highlight it and type close curly) the code gets reformatted to your default style set in your editor. a lot simpler then posting messages complaining and insisting 'your way is better for everybody' I can tell you, without even seeing it: your way is crap, that is it's crap to everybody except yourself, just as mine is crap for anybody but me. And yes, your company guidelines are crap too, to anyone except the pillock who created the 'guidelines'; AKA 'somebody with way too much free time' - and you should tell him that - do some bloody real/proper work instead of wasting time making other peoples lives miserable. Help make the world a better place: Stop bitching about other peoples ways, particularly when there's simple tools that in seconds let you 'fix it' and carry on your own way - these things matter not at all. And for sure, one day, when you get promoted: just DON'T become that jerk-off that creates "company coding standards" and other such nonsense; leave it, get a life, and let other people have theirs too.
-
Yes you are an old fart, who cares what other people source looks like... Using a decent editor (even the Visual Studio editor does this): just go to the last close curly delete it, then put it back (or just highlight it and type close curly) the code gets reformatted to your default style set in your editor. a lot simpler then posting messages complaining and insisting 'your way is better for everybody' I can tell you, without even seeing it: your way is crap, that is it's crap to everybody except yourself, just as mine is crap for anybody but me. And yes, your company guidelines are crap too, to anyone except the pillock who created the 'guidelines'; AKA 'somebody with way too much free time' - and you should tell him that - do some bloody real/proper work instead of wasting time making other peoples lives miserable. Help make the world a better place: Stop bitching about other peoples ways, particularly when there's simple tools that in seconds let you 'fix it' and carry on your own way - these things matter not at all. And for sure, one day, when you get promoted: just DON'T become that jerk-off that creates "company coding standards" and other such nonsense; leave it, get a life, and let other people have theirs too.
ffs, all I did was solicit opinions.... Robert, please take your meds and go to your quiet place... :)
Charlie Gilley Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
-
John Simmons / outlaw programmer wrote:
In the absence of an established corporate coding standard, when editing an existing file, you should always adapt the style already used in the file.
Generally speaking, yes, and I'd never consider reformatting someone's code because they use a different style but I must confess that when I come across a really badly formatted SQL script - all random indents and inconsistent capitilisation combined with rubbish aliases and so forth - I just can't stop myself from tidying it up. It's a little ironic in that I can't remember when I last tidied my desk (or my house for that matter) but messy code annoys the living daylights out of me.
I am forever reformatting other peoples SQL code (or generated SQL). I have may own format rules, and once I get it in that format I can read it easy. Unformatted, I can't make nor tail of it.
-
Here we go.... :) On a more serious note, I've seen both coding styles, and I despise #2. It just makes the code harder to read - *to me*. Am I just an old fart? I read an actual flaming rant about CamelCase (this is not) vs. camelCase (camels have humps in the middle). So, I finally get that. But the curlies? jumping into fox hole now.
Charlie Gilley Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
To be sure, I can't read Melody's style at all. I associate that code style with idiots who just keep jamming random code in until something happens ...
-
Here we go.... :) On a more serious note, I've seen both coding styles, and I despise #2. It just makes the code harder to read - *to me*. Am I just an old fart? I read an actual flaming rant about CamelCase (this is not) vs. camelCase (camels have humps in the middle). So, I finally get that. But the curlies? jumping into fox hole now.
Charlie Gilley Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
I like #1 but actually use #2 in practice.
{To-do: fill section with wit}