I really don't think there's any reason to get personal here.
Printable View
Stop me if I'm wrong, but that document is mostly rules about the content of code, and has very little on about style per say...
At best, it says:
*1 variable declaration per line.
*1 statement per line.
* the "&" and "*" symbols when declariung variables should be attached to the type (and not the variables)
Doesn't really say where to put brackets and how to indent.
----
Over the years, I've found that the best coding standard is simply to code with exactly the same standard being used in the current document you are in:
*If it is a brand new file, knock yourself out
*When editing an existing file, and not following the current style, then you are making a mess of things.
The message may have been lost in translation because of nuzzle's rather fierce response, but if we refer to the source, Stroustrup states that "the main point of a C++ coding standard is to provide a set of rules for using C++ for a particular purpose in a particular environment." He goes on to say that "design issues (...) are far more important than the choice of layout style". So, you were apparently mainly looking out for layout style with respect to indentation and brace placement and hence missed the stuff on naming conventions and various other aspects of style.Quote:
Originally Posted by monarch_dodra
Don't get me wrong, I've read that document end-to-end many times before, and even made some of my colleagues read it :thumb:
I'm just saying it appeared to me as if this argument started out on a minor style argument, and then this document came up...
That said, I don't usually completely read arguments, so I may have been off topic, sorry.
----
As for the "return in the middle of the function issue", I've always thought it is more of a matter of context and what the reader expects. I've always proffered the "bullet list of check, else return", then the monolithic "if-if-if-if-if-if-if-do-something-giant-diagonal-line-of-closing-brackets" (link)
Even if what you wrote compiled, I fail to see how that would be easier to read. I find the ternary / conditional operator to be a weird syntax for someone to read. I've recently noticed that this was observed by those who worked on the python project and they specifically avoided that kind of syntax due to it being hard to read. The python way of doing the equivalent is far more intuitive. That being said, I would personally avoid the C++ conditional operator in that example for the same reasons as others have indicated. In other words, I'd only use it for very simple kinds of expressions. There is really nothing wrong with writing out the if..else blocks and that is much clearer, even if it is more verbose. That's just my two cents, and that is only my opinion.