TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Google C++ style guide

39 pointsby degioabout 11 years ago

15 comments

fhd2about 11 years ago
The C++ you end up with by following Google&#x27;s style guide is more of a &quot;C with classes&quot; 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.<p>But it&#x27;s not exactly a style guide I&#x27;d follow strictly in a new project&#x2F;team.
评论 #7564911 未加载
评论 #7565118 未加载
评论 #7565143 未加载
评论 #7566198 未加载
shmerlabout 11 years ago
<i>&gt; Functions should start with a capital letter and have a capital letter for each new word. No underscores.</i><p>Why so? It&#x27;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&#x27;s a matter of preference, I just wonder why Google mandates camel notation.
评论 #7565025 未加载
评论 #7564972 未加载
ajtullochabout 11 years ago
For those who are unaware, `clang-format` (<a href="http://clang.llvm.org/docs/ClangFormat.html" rel="nofollow">http:&#x2F;&#x2F;clang.llvm.org&#x2F;docs&#x2F;ClangFormat.html</a>) can be used to automatically convert existing C++ code to a given formatting style (Google, LLVM, a custom style, etc).<p>It&#x27;s similar to `gofmt` in the golang world, and is a really useful tool for enforcing these kind of style guides.
mmaldackerabout 11 years ago
No lambdas allowed? For many other things they say &quot;use within reason&quot;, I don&#x27;t see why they can&#x27;t say this for lambdas. They&#x27;re finally making the stl algorithms easily usable. You don&#x27;t have to write Functors that are in a different place then called.<p>Also, the guide seems to completely miss templates and actually pretty much allow everything in C++ (except lambdas and exceptions). I don&#x27;t really see the point then.
评论 #7564683 未加载
评论 #7564845 未加载
评论 #7564669 未加载
NickHoltabout 11 years ago
There&#x27;s a few style guides up the path for those interested: <a href="http://google-styleguide.googlecode.com/svn/trunk/" rel="nofollow">http:&#x2F;&#x2F;google-styleguide.googlecode.com&#x2F;svn&#x2F;trunk&#x2F;</a>
greggmanabout 11 years ago
As an x googler I had my issues with it<p><a href="http://games.greggman.com/game/lets-debate-coding-style/" rel="nofollow">http:&#x2F;&#x2F;games.greggman.com&#x2F;game&#x2F;lets-debate-coding-style&#x2F;</a>
eksithabout 11 years ago
&quot;Use only spaces, and indent 2 spaces at a time.&quot; Of course you realize, this means war.<p>Much like all other style guides I&#x27;ve come across, there are a lot of hints that I&#x27;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.<p>And, I&#x27;m not sure if this is just those who share the same water cooler, many C++ devs seem to dislike using STL. I can&#x27;t figure out why.
评论 #7565434 未加载
cubbimewabout 11 years ago
It doesn&#x27;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 &quot;insidious&quot;). Not even mentioning the FUD about newer C++ features.
nemasuabout 11 years ago
I 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.
评论 #7565158 未加载
评论 #7564896 未加载
评论 #7564898 未加载
评论 #7564787 未加载
评论 #7564912 未加载
评论 #7564775 未加载
评论 #7564874 未加载
patchhillabout 11 years ago
Looking at this style guide as a C++ programmer, I&#x27;d hate to work at Google.
joshvmabout 11 years ago
FYI, the lint tool referenced in the guide is found here:<p><a href="http://google-styleguide.googlecode.com/svn/trunk/cpplint/" rel="nofollow">http:&#x2F;&#x2F;google-styleguide.googlecode.com&#x2F;svn&#x2F;trunk&#x2F;cpplint&#x2F;</a>
shin_laoabout 11 years ago
It might sound like a good idea to precisely describe how code should be written, until you realize it&#x27;s inefficient and useless.<p>Code coherence can be accomplished with more relaxed rules if you delegate more responsibility to your engineers.
评论 #7564652 未加载
评论 #7564931 未加载
teemo_cuteabout 11 years ago
&quot;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.&quot;<p>—String and Wire (Elements of Modern Programming Style)
frozenportabout 11 years ago
C++ Guide: We do not use C++ exceptions.<p>Python Guide: Exceptions are allowed but must be used carefully.<p>C++ Guide: Do not use lambda expressions, std::function or std::bind.<p>Python Guide: Okay for one-liners.
评论 #7565091 未加载
frozenportabout 11 years ago
Does Google&#x27;s 80 character limit include the identification sequence?
评论 #7565177 未加载