The C++ you end up with by following Google's style guide is more of a "C with classes" thing, they prohibit several central features of C++. That said, I understand that they mostly do this to be consistent with their older code bases.
But it's not exactly a style guide I'd follow strictly in a new project/team.
You're right on the money. This passage is particularly damning:
> Rvalue references encourage a programming style that makes heavier use of value semantics. This style is unfamiliar to many developers, and its performance characteristics can be hard to reason about.
It's like, do you know C++ or don't you? Value semantics are C++.
Actually they do prohibit those features that arguably cause more damage than benefit.
c++ exceptions? in an unmanaged (runtime engine not managed by some sort of VM) language you can't really assume anything when an exception occurs, you can't assume that you will be able to allocate more memory from the heap, for instance - if the heap is corrupted then this will just not work.
RTTI ? it costs a lot, well and you can do without it; Besides requirement of RTTI (assuming that the library does RTTI) will prevent you from using third party libraries that might be of use. Resolution: skip.
It's a totally reasonable style guide to adopt with a new project / team. And in fact it's what I chose the last time I started a team doing systems programming. It's well reasoned, and hits my personal sweet spot for the power vs. complexity tradeoff.
C++ has a pretty bad reputation. Possibly deservedly. So unless everyone has already bought fully into C++, the full language is a very hard sell. But C with a few extra conveniences and safety features (strings, unique_ptr, some limited polymorphism) is a much easier one.
> Functions should start with a capital letter and have a capital letter for each new word. No underscores.
Why so? It's Java-ish. Java favors camel notation for some historic reason. C++ on the other hand favors snake notation which is clearly reflected in stdc++. Snake notation is also easier to read, especially if the name contains many words in it. Of course in the end it's a matter of preference, I just wonder why Google mandates camel notation.
This is actually the main advantage of having detailed coding style guide. Teams don't need to discuss minor details like this over and over again, and can focus on higher level issues. Style rules can be sometimes arbitrary because there is no clear best approach, but it is important that such arbitrary choices are made once, documented, and consistently enforced.
>Snake notation is also easier to read, especially if the name contains many words in it. Of course in the end it's a matter of preference.
Exactly. It's matter of preference. I can read TextLikeThis much easier than text_like_this. Granted I've been developing in C# for past few years so that's likely the reason.
For those who are unaware, `clang-format` (http://clang.llvm.org/docs/ClangFormat.html) can be used to automatically convert existing C++ code to a given formatting style (Google, LLVM, a custom style, etc).
It's similar to `gofmt` in the golang world, and is a really useful tool for enforcing these kind of style guides.
No lambdas allowed? For many other things they say "use within reason", I don't see why they can't say this for lambdas. They're finally making the stl algorithms easily usable. You don't have to write Functors that are in a different place then called.
Also, the guide seems to completely miss templates and actually pretty much allow everything in C++ (except lambdas and exceptions). I don't really see the point then.
> They're finally making the stl algorithms easily usable.
Well, considering they ban use of exceptions and considering that stl does use exceptions and therefore they cannot use stl, I don't think that they really care.
This is an older revision of the style guide; they updated the style guide recently to allow lambdas. Other C++11 features were also under review for a while.
"Use only spaces, and indent 2 spaces at a time." Of course you realize, this means war.
Much like all other style guides I've come across, there are a lot of hints that I'll find helpful and encourage at our next meetup, but honestly, the only style guide that truly matters is the one you can all agree to in your team and makes sense in your context.
And, I'm not sure if this is just those who share the same water cooler, many C++ devs seem to dislike using STL. I can't figure out why.
It doesn't get any worse than that guide (except maybe EC++ or the FQA).
No RAII, no class invariants, no value semantics, no streams, no operators (which means no custom Iterators, EqualityComparable or even CopyAssignable types! Such a basic feature called "insidious").
Not even mentioning the FUD about newer C++ features.
I don't really see a lot to like about C++. It's huge and fiendishly complex, keywords are overloaded to incomprehensibility, it doesn't make satisfactory guarantees about static initialization, exception safety is too hard to reason about, it's full of features maintained for backwards compatibility even when they no longer make sense, and development tools are unacceptably inferior to Java and C#.
Pros are that it performs excellently and const correctness is pretty cool.
Still the language of choice in the world of music production software. This is not a place you'll make a lot of money but the work is far more interesting than the usual CRUD slapdash you do in most dev shops.
Some coding style guides amount to an obsessive compulsive disorder. They focus on trivialities, like an extra space between parameters or the placement of braces around blocks of code.
"Vigorous programming is concise. A method should contain no unnecessary statements, a class no unnecessary methods, for the same reason that a drawing should have no unnecessary lines and a machine no unnecessary parts. This requires not that the programmer make all his methods short, or that he avoid all detail and treat his classes only in design, but that he make every statement tell."
—String and Wire (Elements of Modern Programming Style)
I've encountered a lot of c++ programmers who seem to dislike a lot of c++; even refusing to use the STL. Perhaps it's because c++ and Python have different cultural backgrounds: a lot of early c++ programmers came over grudgingly from c and continued to program in a c-style.
[+] [-] fhd2|12 years ago|reply
But it's not exactly a style guide I'd follow strictly in a new project/team.
[+] [-] bjz_|12 years ago|reply
[+] [-] brianpgordon|12 years ago|reply
> Rvalue references encourage a programming style that makes heavier use of value semantics. This style is unfamiliar to many developers, and its performance characteristics can be hard to reason about.
It's like, do you know C++ or don't you? Value semantics are C++.
[+] [-] MichaelMoser123|12 years ago|reply
c++ exceptions? in an unmanaged (runtime engine not managed by some sort of VM) language you can't really assume anything when an exception occurs, you can't assume that you will be able to allocate more memory from the heap, for instance - if the heap is corrupted then this will just not work.
RTTI ? it costs a lot, well and you can do without it; Besides requirement of RTTI (assuming that the library does RTTI) will prevent you from using third party libraries that might be of use. Resolution: skip.
[+] [-] jsnell|12 years ago|reply
C++ has a pretty bad reputation. Possibly deservedly. So unless everyone has already bought fully into C++, the full language is a very hard sell. But C with a few extra conveniences and safety features (strings, unique_ptr, some limited polymorphism) is a much easier one.
[+] [-] shmerl|12 years ago|reply
Why so? It's Java-ish. Java favors camel notation for some historic reason. C++ on the other hand favors snake notation which is clearly reflected in stdc++. Snake notation is also easier to read, especially if the name contains many words in it. Of course in the end it's a matter of preference, I just wonder why Google mandates camel notation.
[+] [-] mixedbit|12 years ago|reply
[+] [-] romanovcode|12 years ago|reply
Exactly. It's matter of preference. I can read TextLikeThis much easier than text_like_this. Granted I've been developing in C# for past few years so that's likely the reason.
[+] [-] ajtulloch|12 years ago|reply
It's similar to `gofmt` in the golang world, and is a really useful tool for enforcing these kind of style guides.
[+] [-] mmaldacker|12 years ago|reply
Also, the guide seems to completely miss templates and actually pretty much allow everything in C++ (except lambdas and exceptions). I don't really see the point then.
[+] [-] adamnemecek|12 years ago|reply
Well, considering they ban use of exceptions and considering that stl does use exceptions and therefore they cannot use stl, I don't think that they really care.
[+] [-] exacube|12 years ago|reply
[+] [-] SamReidHughes|12 years ago|reply
[+] [-] NickHolt|12 years ago|reply
[+] [-] greggman|12 years ago|reply
http://games.greggman.com/game/lets-debate-coding-style/
[+] [-] eksith|12 years ago|reply
Much like all other style guides I've come across, there are a lot of hints that I'll find helpful and encourage at our next meetup, but honestly, the only style guide that truly matters is the one you can all agree to in your team and makes sense in your context.
And, I'm not sure if this is just those who share the same water cooler, many C++ devs seem to dislike using STL. I can't figure out why.
[+] [-] yoklov|12 years ago|reply
1. Holdover from when STL implementations were buggy
2. Holdover from C
3. Avoiding exceptions it might throw if you compile with exceptions off
4. Many STLs are slow and unoptimized.
5. Many parts of the STL are slow, no matter which STL you use
6. Poor allocator support (better, not perfect in c++11)
7. You need guarantees that the STL doesnt provide.
there are more, but those are the big ones.
[+] [-] cubbimew|12 years ago|reply
[+] [-] nemasu|12 years ago|reply
[+] [-] brianpgordon|12 years ago|reply
Pros are that it performs excellently and const correctness is pretty cool.
Let's get an old fashioned debate started!
[+] [-] anonymousDan|12 years ago|reply
[+] [-] cageface|12 years ago|reply
[+] [-] pjmlp|12 years ago|reply
[+] [-] zura|12 years ago|reply
[+] [-] xedarius|12 years ago|reply
[+] [-] ddorian43|12 years ago|reply
[+] [-] patchhill|12 years ago|reply
[+] [-] joshvm|12 years ago|reply
http://google-styleguide.googlecode.com/svn/trunk/cpplint/
[+] [-] shin_lao|12 years ago|reply
Code coherence can be accomplished with more relaxed rules if you delegate more responsibility to your engineers.
[+] [-] adamnemecek|12 years ago|reply
Please elaborate.
[+] [-] skia|12 years ago|reply
[+] [-] teemo_cute|12 years ago|reply
—String and Wire (Elements of Modern Programming Style)
[+] [-] frozenport|12 years ago|reply
Python Guide: Exceptions are allowed but must be used carefully.
C++ Guide: Do not use lambda expressions, std::function or std::bind.
Python Guide: Okay for one-liners.
[+] [-] archena|12 years ago|reply
[+] [-] frozenport|12 years ago|reply
[+] [-] brianpgordon|12 years ago|reply