It is great to have such a collection of rules and I hope they will be integrated into some easy-to-integrate static code analysis tool (as mentioned in the introduction). Maybe this will help people to transition to more modern C++ and to avoid some pitfalls (e.g. forgetting the "noexcept" for move constructors/assignments).<p>However, in some respect this list also shows what is wrong with C++: The fact that you even need such a huge set of rules to write safe and efficient code is somewhat unsettling. I'd rather hope a new version of the language standard would at least allow to hide deprecated constructs behind a "safe/unsafe" pragma.
I'm only a bit in but I've already found myself disagreeing with some of these<p>for example<p><pre><code> drawline(int,int,int,int); // obscure
drawline(Point,Point); // clearer
</code></pre>
this is only "clearer" until you find yourself at the very common case where you use several libraries where each defines its own "Point".<p>Now you're writing something like<p><pre><code> drawline(Point(vec.x1, vec.y1), Point(vec.x2, vec.y2))
</code></pre>
Pretty ugly!<p>And of course drawline(Point, Point) isn't clearer at all imo. What's the coordinate system? What are the units? Any performance notes on this function? Etc. I'll be checking the documentation the first time anyway.<p><pre><code> void do_something(vector<string>& v)
{
string val;
cin>>val;
// ...
int index = 0; // bad
for(int i=0; i<v.size(); ++i)
if (v[i]==val) {
index = i;
break;
}
// ...
}</code></pre>
this is shown to be inferior to the find() version. Again, it's only inferior until the very common case where you're doing something else with the index, which is pretty common during debugging. Then you'll be rewriting the above "bad" version anyway.<p>Similar problems other higher order functions like for_each().
All these guidelines are good for those who have been in C++ trenches for a while. For others, it will become another list, a list similar to what non-native English speakers have to learn by rote in order to predict the pronunciation of English words.<p>We have Scott Meyer's effective c++, more effective c++, effective STL, effective STL, modern effective c++.<p>I have read Bjarne's "A tour of C++", which is a good one to read. Also read his "design and evolitution of C++", which gives rationale for what we see the ugliness of C++.<p>I think we need a small book that describes the history of C++ until now, such a book can help us to remember "C++ core guidelines". This is similar to how great vowel shift in the history of Enlgih langauge helps us to see deeper patterns in English pronunciation.<p>I hate a bunch of guidelines, without historical explanations, because such guidelines are very hard to pin to one's brain unless one is working in hardcare C++ everyday. Maybe, this sounds like playing Piano scales:)
It's amazing how many people get these core principles wrong. I recently visited a C++ shop who hasn't even heard of RAII and don't use smart pointers or standard containers. What a nightmare.<p>It's great to see C++ getting an ecosystem and Bjarne's excellent writings help a lot.
The more I develop in C++, the more I wish I had a very restructure transpirer that would remove some of its most silly constructs or switch ite base defaults around.<p>Some examples:
- making all constructors explicit and adding an implicit keyword instead for that rare case
- automatically generated !=, <=, >= etc from == and < (with an explicit override when you want to be silly)
- removing some of the redundant syntaxes (const positioning, typedefs vs using etc
- removing the class keyword
>This document is a very early draft. It is inkorrekt, incompleat, and pµøoorly formatted.<p>It's the little things in life that make it so great.
I must confess I am tired of all these guidelines. I mean I have learned C++ once, gone through the ordeal of learning all the best practices, memorizing all the gotchas etc. And now the language just got bigger. New features arrived along with new unexpected gotchas. Scott Meyers has written a new book and all is well. Except that the more C++ I write the more I yearn for something simpler with less arbitrary rules to memorize.
I wonder how many of these could be implemented in clang tidy:<p><a href="http://clang.llvm.org/extra/clang-tidy/index.html" rel="nofollow">http://clang.llvm.org/extra/clang-tidy/index.html</a>
I first started looking at this when Cfront by AT&T Bell Telephone Laboratories came out. Let me know when the language stabilizes and maybe I'll take a look at it again.
That's what I really value about Go: gofmt and very good linting that embraces best practices. I know C++ is way more complex but for someone starting out it seems impossible to code in the "right (tm)" style.
started losing me at exceptions. the philosophy bit is quite nice, but seeing auto in the example... not for me. not even close.<p>its a shame we are ruining C++. can't we just have something better... :/
P.4 mentions using variant, but I couldn't find any information on this. Does standard C++ have a built in variant now?<p>If so, could someone link me to a resource?