20 ms·
Google C++ style guide
- teemo_cute 13y ago"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)
- mmaldacker 13y agoNo 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.
- SamReidHughes 13y agoThey don't even want you to use rvalue references.
- adamnemecek 13y ago> 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.
- IvyMike 13y agoI suspect they either use an STL that has a way to disable exceptions (such as STLPort) or they disable exceptions using compiler flags, or maybe both. You may argue that this really brings into question the "S" part of "STL" but it is done in practice and I'd argue it's not even all that difficult to deal with.
- pbsd 13y agoAccording to this StackOverflow reply [1], they do use the STL, but don't catch the (very rare) exceptions. [1] https://stackoverflow.com/a/15564254 https://stackoverflow.com/a/15564254
- exacube 13y agoThis 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.
- shin_lao 13y agoIt might sound like a good idea to precisely describe how code should be written, until you realize it's inefficient and useless. Code coherence can be accomplished with more relaxed rules if you delegate more responsibility to your engineers.
- adamnemecek 13y ago> Code coherence can be accomplished with more relaxed rules if you delegate more responsibility to your engineers. Please elaborate.
- shin_lao 13y agoI think consensus through code review is better as compilers and languages evolve. If you write rules for everything you spend your time checking for compliance and perhaps rewriting rules instead of relying on a more organic code quality assurance. You also want your engineers to think by themselves instead of hiding behind a rules book.
- cloudwalking 13y agoCode style doesn't dictate what your engineers build, it just makes their code easier to review and maintain. Code smells, foreign conventions, and inconsistency all make reviewing and editing code harder.
- skia 13y agoSome 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.
- nemasu 13y agoI love C++, I wish there was more work available that used it. EDIT: Clearly my issue is where I lived, not the lack of available jobs apparently.
- xedarius 13y agoGames programmer!
- nemasu 13y agoYeah, this is true. But all places pretty much require you have prior experience. Not to mention most games these days are in Obj-c/Java. Plus game studios aren't exactly ubiquitous (least not where I'm from).
- fhd2 13y ago> Not to mention most games these days are in Obj-c/Java. Proof? I've seen _quite_ the opposite. Sure, these things (and Flash, still) are popular among small/indie devs, but I haven't heard about a single AAA title since ~1995 that didn't used C++. There is an insane amount of big open source projects out there that use C++. Firefox, Chromium, KDE, .... the list is much longer. Making significant contributions to any of those would most likely be considered experience. And there are tons of C++ jobs outside the game industry. Not for small-scale web stuff of course, but for client-side stuff, and really huge backends, C++ is still very popular.
- nemasu 13y agoNo proof really. My last job hunt ( Nov of last year ) just came up 100% not-C++, currently doing Java work. Same thing happened a few years ago...maybe I just lived in a lame city though.
- zura 13y agoSpeaking about remote C++ jobs - I sent an email to you more than two months ago, for the C++ dev position at Eyeo, which they still advertise on their jobs site. I sent again after a couple of weeks. No reply. Could you please confirm that this job is still active?
- NickHolt 13y agoThere's a few style guides up the path for those interested: http://google-styleguide.googlecode.com/svn/trunk/ http://google-styleguide.googlecode.com/svn/trunk/
- fhd2 13y agoThe 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.
- bjz_ 13y agoThe Google style guide could help explain why the Go team thought that their language would make more of an impact in C++ land than it actually did.
- dsymonds 13y agoNope. Go was born because large C++ builds were just too darn slow, but that wasn't due to using a restricted subset of C++. In fact, using a subset of C++ speeds the build up.
- brianpgordon 13y agoYou'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++.
- fauigerzigerk 13y agoThey are right that it's harder to reason about value semantics. The cost of passing a pointer is always the same whereas the cost of passing a value isn't. But I don't think that's a good enough reason not to prefer values considering the performance and memory usage drawbacks of shared_ptr. unique_ptr is often the best solution in my view.
- MichaelMoser123 13y agoActually 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.
- greggman 13y agoAs an x googler I had my issues with it http://games.greggman.com/game/lets-debate-coding-style/ http://games.greggman.com/game/lets-debate-coding-style/
- shmerl 13y ago> 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.
- romanovcode 13y ago>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.
- yoklov 13y agoI don't have a strong opinion either way (I probably like snake case more, but use camel/pascal case basically everywhere) but this doesn't work as well when acronyms are involved. e.g. is it XmlParser or XMLParser? I'd say the latter, but someone else might disagree. I think there are more ambiguous examples, but cant think of them.
- romanovcode 13y ago> is it XmlParser or XMLParser? MS standards says that if shortened letter combination is longer than 2 words than it's lowered, otherwise everything is uppercase. e.g. XmlParser, IOStream But again, everyone can create their own standard and be happy. The only problem occurs when you work with 10 people and everyone is sticking to his own style.
- yoklov 13y agoNot every API is that consistent. JavaScript's `XMLHttpRequest`, for example...
- joshvm 13y agoFYI, the lint tool referenced in the guide is found here: http://google-styleguide.googlecode.com/svn/trunk/cpplint/ http://google-styleguide.googlecode.com/svn/trunk/cpplint/
- frozenport 13y agoC++ Guide: We do not use C++ exceptions. 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 13y agoI'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.
- frozenport 13y agoDoes Google's 80 character limit include the identification sequence?
- brianpgordon 13y agoYou'd think that with their mountains of cash Google could afford to replace their engineers' 80-character monochrome terminals.
- dsymonds 13y agoActually you find that many engineers with 30" monitors end up using multiple side-by-side terminal windows, each set to 80 chars.
- patchhill 13y agoLooking at this style guide as a C++ programmer, I'd hate to work at Google.
- ajtulloch 13y agoFor those who are unaware, `clang-format` (http://clang.llvm.org/docs/ClangFormat.html 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.
- eksith 13y ago"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.
- yoklov 13y agoThe big reasons for avoiding the STL are (in my experience) 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 13y agoIt 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.