The only thing worse than code written using The Wrong Brace Style(tm)
-
JimmyRopes wrote:
The real question is does the code function properly? :rolleyes:
Which part of...
Quote:
For my sins I'm investigating the possibility of porting one of my employer's apps to the BB10 platform
... id you not understand?
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:
Which part of...For my sins I'm investigating the possibility of porting one of my employer's apps to the BB10 platform...id you not understand?
I id understand you were porting it to a BB10 platform which makes it important that the code functions properly or you will be porting code that does not meet the functionality of the application. Which part of...
JimmyRopes wrote:
The real question is does the code function properly? :rolleyes:
... id you not understand? :doh:
The report of my death was an exaggeration - Mark Twain
Simply Elegant Designs JimmyRopes Designs
Think inside the box! ProActive Secure Systems
I'm on-line therefore I am. JimmyRopes -
... is code that is written using a mix of brace styles. For my sins I'm investigating the possibility of porting one of my employer's apps to the BB10 platform; and most of the sample app code they've provided looks like this:
PhotoBomberApp::PhotoBomberApp()
{
// Create a QMLDocument and load it, using build patterns
QmlDocument *qml = QmlDocument::create("asset:///main.qml");qml->setContextProperty("\_photoBomber", this); if (!qml->hasErrors()) { // The application Page is created from QML. Page \*appPage = qml->createRootObject<Page>(); if (appPage) { // Set the application scene. Application::instance()->setScene(appPage); } }
}
Some opening braces on their own line; others on the preceding line. **SPEW**[^]
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
To me there often is much more to get upset on than brace styles. I can deal with every style (as long as it is the same style in the whole module of course). Meaningless variable names or code with a lot of untreated warnings from the compiler (deserts of trivial to solve warnings hiding the really important one) - that drives me nuts! Brace styles? No, not really...
-
Whitesmith's rules! I never seize to amaze over the triviality of this eternal style format discussion. Who is to say one style is better or worse than another? Is it not more important that the code is A. readable, B. intuitive, C. Bug Free! What I truly detest in coding style is all the code written as if programmers were paid by each line of code (ancient format of reimbursement) and everyone simply tries to fill a load of dead line space whilst appearing smart. This entire theme of discussion is in my years of writing code simply for small talk on coffee breaks and not really adding functionality in my personal opinion.
MRJIT wrote:
What I truly detest in coding style is all the code written as if programmers were paid by each line of code (ancient format of reimbursement) and everyone simply tries to fill a load of dead line space whilst appearing smart.
Oddly, what I truly detest in coding style is the code packed so tightly as to be completely inscrutable to any other programmer --- to appear smart.
Truth, James
-
... is code that is written using a mix of brace styles. For my sins I'm investigating the possibility of porting one of my employer's apps to the BB10 platform; and most of the sample app code they've provided looks like this:
PhotoBomberApp::PhotoBomberApp()
{
// Create a QMLDocument and load it, using build patterns
QmlDocument *qml = QmlDocument::create("asset:///main.qml");qml->setContextProperty("\_photoBomber", this); if (!qml->hasErrors()) { // The application Page is created from QML. Page \*appPage = qml->createRootObject<Page>(); if (appPage) { // Set the application scene. Application::instance()->setScene(appPage); } }
}
Some opening braces on their own line; others on the preceding line. **SPEW**[^]
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
This is K&R - other than the if (appPage) not needing braces at all. Nothing wrong here. Move along.
-
Whitesmith's rules! I never seize to amaze over the triviality of this eternal style format discussion. Who is to say one style is better or worse than another? Is it not more important that the code is A. readable, B. intuitive, C. Bug Free! What I truly detest in coding style is all the code written as if programmers were paid by each line of code (ancient format of reimbursement) and everyone simply tries to fill a load of dead line space whilst appearing smart. This entire theme of discussion is in my years of writing code simply for small talk on coffee breaks and not really adding functionality in my personal opinion.
MRJIT wrote:
Is it not more important that the code is A. readable...
Yes readability does matter, and that's exactly why brace style matters.
MRJIT wrote:
What I truly detest in coding style is all the code written as if programmers were paid by each line of code (ancient format of reimbursement) and everyone simply tries to fill a load of dead line space whilst appearing smart.
I have never understood the desire to save vertical space. Can anyone tell me why, in this day and age, vertical space is so important that it's worth sacrificing readability for? The best brace style is the most readable one, and also the one that is least likely to get mangled during refactoring. Allman, of course.
-
... is code that is written using a mix of brace styles. For my sins I'm investigating the possibility of porting one of my employer's apps to the BB10 platform; and most of the sample app code they've provided looks like this:
PhotoBomberApp::PhotoBomberApp()
{
// Create a QMLDocument and load it, using build patterns
QmlDocument *qml = QmlDocument::create("asset:///main.qml");qml->setContextProperty("\_photoBomber", this); if (!qml->hasErrors()) { // The application Page is created from QML. Page \*appPage = qml->createRootObject<Page>(); if (appPage) { // Set the application scene. Application::instance()->setScene(appPage); } }
}
Some opening braces on their own line; others on the preceding line. **SPEW**[^]
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
Well, at least you have braces, they could have resorted to not use braces in the last if. :)
CEO at: - Rafaga Systems - Para Facturas - Modern Components for the moment...
-
... is code that is written using a mix of brace styles. For my sins I'm investigating the possibility of porting one of my employer's apps to the BB10 platform; and most of the sample app code they've provided looks like this:
PhotoBomberApp::PhotoBomberApp()
{
// Create a QMLDocument and load it, using build patterns
QmlDocument *qml = QmlDocument::create("asset:///main.qml");qml->setContextProperty("\_photoBomber", this); if (!qml->hasErrors()) { // The application Page is created from QML. Page \*appPage = qml->createRootObject<Page>(); if (appPage) { // Set the application scene. Application::instance()->setScene(appPage); } }
}
Some opening braces on their own line; others on the preceding line. **SPEW**[^]
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
The Sherlock comments are certainly annoying. //Add a and b var result = a + b; //Save the result result.Save(); // Mønti Pythøn ik den Hølie Gräilen Røtern nik Akten Di Wik Alsø wik Alsø alsø wik Wi nøt trei // a høliday in Sweden this yër? See the løveli lakes The wøndërful telephøne system And mäni // interesting furry animals The characters and incidents portrayed and the names used are fictitious // and any similarity to the names, characters, or history of any person is entirely accidental and // unintentional. System.Diagnostics.Debug.WriteLine(result.ToString());
-
... is code that is written using a mix of brace styles. For my sins I'm investigating the possibility of porting one of my employer's apps to the BB10 platform; and most of the sample app code they've provided looks like this:
PhotoBomberApp::PhotoBomberApp()
{
// Create a QMLDocument and load it, using build patterns
QmlDocument *qml = QmlDocument::create("asset:///main.qml");qml->setContextProperty("\_photoBomber", this); if (!qml->hasErrors()) { // The application Page is created from QML. Page \*appPage = qml->createRootObject<Page>(); if (appPage) { // Set the application scene. Application::instance()->setScene(appPage); } }
}
Some opening braces on their own line; others on the preceding line. **SPEW**[^]
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
-
Whitesmith's rules! I never seize to amaze over the triviality of this eternal style format discussion. Who is to say one style is better or worse than another? Is it not more important that the code is A. readable, B. intuitive, C. Bug Free! What I truly detest in coding style is all the code written as if programmers were paid by each line of code (ancient format of reimbursement) and everyone simply tries to fill a load of dead line space whilst appearing smart. This entire theme of discussion is in my years of writing code simply for small talk on coffee breaks and not really adding functionality in my personal opinion.
IMHO - the goal of formatting is to make the structure of the code visible, explicit, so the reader does not have to dig into the code and try to decipher its structure. Some people have the naive view that formatting as merely "pretty printing" or making the code neat and tidy. This leads to inconsistent formatting conventions and the mistaken idea that formatting is a matter of individual style rather than an engineering topic. Making the code pretty with an individual style only accomplishes half of the goal of making the structure explicit. It does not provide a basis for a consistent set of guidelines for the formatting.
-
... is code that is written using a mix of brace styles. For my sins I'm investigating the possibility of porting one of my employer's apps to the BB10 platform; and most of the sample app code they've provided looks like this:
PhotoBomberApp::PhotoBomberApp()
{
// Create a QMLDocument and load it, using build patterns
QmlDocument *qml = QmlDocument::create("asset:///main.qml");qml->setContextProperty("\_photoBomber", this); if (!qml->hasErrors()) { // The application Page is created from QML. Page \*appPage = qml->createRootObject<Page>(); if (appPage) { // Set the application scene. Application::instance()->setScene(appPage); } }
}
Some opening braces on their own line; others on the preceding line. **SPEW**[^]
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
The only answer is to switch to Fortran. If you still complain about K&R style after that, then you are far more resilient than I. :)
-
OriginalGriff wrote:
Reformat the whole lot to Whitesmiths style!
I came to C/C++ from turbo pascal - so naturally I did C/C++ in the Whitesmiths style ... I still guess that the primary reason for
void foo() {
}was the 12" monitors of yesteryears ... On the other hand, I guess the best reason for having a coding style-guide is to avoid wasting time discussing coding styles.
Espen Harlinn Principal Architect, Software - Goodtech Projects & Services AS Projects promoting programming in "natural language" are intrinsically doomed to fail. Edsger W.Dijkstra
-
The only answer is to switch to Fortran. If you still complain about K&R style after that, then you are far more resilient than I. :)
Hmmmm would writing a mobile app in Fortran get me 15 minutes of fame by getting to the front page of hacker news? I'd say no, except that the person who wrote a web server framework in COBOL[^] succeeded.
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
-
IMHO - the goal of formatting is to make the structure of the code visible, explicit, so the reader does not have to dig into the code and try to decipher its structure. Some people have the naive view that formatting as merely "pretty printing" or making the code neat and tidy. This leads to inconsistent formatting conventions and the mistaken idea that formatting is a matter of individual style rather than an engineering topic. Making the code pretty with an individual style only accomplishes half of the goal of making the structure explicit. It does not provide a basis for a consistent set of guidelines for the formatting.
Member 10475170 wrote:
This leads to inconsistent formatting conventions and the mistaken idea that formatting is a matter of individual style rather than an engineering topic.
It is a matter of individual style. Conversely if you think it is not then presumably you have some objective data to back up the assertion that it provides measured benefit.
-
To me there often is much more to get upset on than brace styles. I can deal with every style (as long as it is the same style in the whole module of course). Meaningless variable names or code with a lot of untreated warnings from the compiler (deserts of trivial to solve warnings hiding the really important one) - that drives me nuts! Brace styles? No, not really...
jaybus56 wrote:
To me there often is much more to get upset on than brace styles
To me anyone that thinks bracing styles makes any difference at all has never worked in any of the industries that I have. There are a vast array of problems that measurably impact the entire process of delivering a useable piece of software. I can only suppose that people that think braces are significant do not deal with any but code and of course are completely unaware of formatting software.
-
Member 10475170 wrote:
This leads to inconsistent formatting conventions and the mistaken idea that formatting is a matter of individual style rather than an engineering topic.
It is a matter of individual style. Conversely if you think it is not then presumably you have some objective data to back up the assertion that it provides measured benefit.
Maintenance programmers everywhere would like a word with you outside.
-
... is code that is written using a mix of brace styles. For my sins I'm investigating the possibility of porting one of my employer's apps to the BB10 platform; and most of the sample app code they've provided looks like this:
PhotoBomberApp::PhotoBomberApp()
{
// Create a QMLDocument and load it, using build patterns
QmlDocument *qml = QmlDocument::create("asset:///main.qml");qml->setContextProperty("\_photoBomber", this); if (!qml->hasErrors()) { // The application Page is created from QML. Page \*appPage = qml->createRootObject<Page>(); if (appPage) { // Set the application scene. Application::instance()->setScene(appPage); } }
}
Some opening braces on their own line; others on the preceding line. **SPEW**[^]
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
I just wish all Version Control Systems would allow us to chose the brace formatting, as well as other formatting, and check the code out into the format we like and check it back in as the company standard. Then this battle could end. :)
-
Espen Harlinn wrote:
is to avoid wasting time discussing coding styles.
Yes, wasting time is much better spent on what the sport team did last weekend and what it will do next weekend.
jschell wrote:
Yes, wasting time is much better spent on what the sport team did last weekend and what it will do next weekend.
True, and everybody knows that we're wasting time, and not pretending to work ;P
Espen Harlinn Principal Architect, Software - Goodtech Projects & Services AS Projects promoting programming in "natural language" are intrinsically doomed to fail. Edsger W.Dijkstra
-
MRJIT wrote:
What I truly detest in coding style is all the code written as if programmers were paid by each line of code (ancient format of reimbursement) and everyone simply tries to fill a load of dead line space whilst appearing smart.
Oddly, what I truly detest in coding style is the code packed so tightly as to be completely inscrutable to any other programmer --- to appear smart.
Truth, James
-
Hmmmm would writing a mobile app in Fortran get me 15 minutes of fame by getting to the front page of hacker news? I'd say no, except that the person who wrote a web server framework in COBOL[^] succeeded.
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
I wouldn't call that fame so much as infamy. I think that you would get some notoriety for it. You may get some public ridicule as well though even if you list that you did it on a lark. I don't know what mobile platform that actually has a compiler for Fortran though unless you roll your own for the NDK for Android. I guess someone has got that working: http://danilogiulianelli.blogspot.com/2013/02/how-to-build-gcc-fortran-cross-compiler.html[^]
-
MRJIT wrote:
Is it not more important that the code is A. readable...
Yes readability does matter, and that's exactly why brace style matters.
MRJIT wrote:
What I truly detest in coding style is all the code written as if programmers were paid by each line of code (ancient format of reimbursement) and everyone simply tries to fill a load of dead line space whilst appearing smart.
I have never understood the desire to save vertical space. Can anyone tell me why, in this day and age, vertical space is so important that it's worth sacrificing readability for? The best brace style is the most readable one, and also the one that is least likely to get mangled during refactoring. Allman, of course.
StatementTerminator wrote:
Can anyone tell me why, in this day and age, vertical space is so important ...
Putting a bunch of filler space does sacrifice readability when you have to scroll up and down to see what it is doing. I'm not complaining about putting a single statement on a single line. I'm talking about putting multiple lines of whitespace so you have 20 commands put in 100 lines of "code".