May 16, 2011

Volker Volker
Robot Herder
5428 posts

Google C++ Style Guide

Page  
1

Some nice reading on the “style” of C++ code at Google open source projects: The Google C++ Style Guide [google-styleguide.googlecode.com]

It has some good technical explanations for various style rules. Others are clearly more a matter of taste type of rules, and are arguable – as always in this sujet :-)

Nontheless, enjoy reading!

19 replies

May 16, 2011

kidproquo kidproquo
Lab Rat
110 posts

How do the Google style guides compare to the Qt style guide? Are they largely consistent?

May 16, 2011

Volker Volker
Robot Herder
5428 posts

I did not compare them thoroughly, but I would say they differ in naming conventions and they do more strictly enforce the rules at all (against Qt which says: follow the rules wherever you can, but feel free to break them here and then where it makes sense).

May 16, 2011

Andre Andre
Area 51 Engineer
6031 posts

Personally, I really like the Qt convention that class names start with a capital, and method names with a lower case letter. That is different in the Google conventions.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

May 16, 2011

Volker Volker
Robot Herder
5428 posts

As a real qt-e developer, I prefer this too, of course :-P

May 16, 2011

Franzk Franzk
Lab Rat
830 posts

They’re a tad too strict for my taste. If you’re going to be telling people where to put their ++, you’re focusing on the wrong thing.

 Signature 

“Horse sense is the thing a horse has which keeps it from betting on people.”—W.C. Fields

http://www.catb.org/~esr/faqs/smart-questions.html

May 16, 2011

Peppy Peppy
Hobby Entomologist
389 posts

Good reading, but some points I’d rather to change…

For example:http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml?showone=Doing_Work_in_Constructors#Doing_Work_in_Constructors

As I am reading more, I am glad to we have Qt “style”…

May 16, 2011

Franzk Franzk
Lab Rat
830 posts

Heh, back to good old plain C again:

  1. Object *o = new Object;
  2. o->init();

  1. struct Object *o = malloc(sizeof(struct Object));
  2. ObjectInit(o);

 Signature 

“Horse sense is the thing a horse has which keeps it from betting on people.”—W.C. Fields

http://www.catb.org/~esr/faqs/smart-questions.html

May 16, 2011

Peppy Peppy
Hobby Entomologist
389 posts

Yes, yes…C# uses it too ((void) Init() functions)

Google Style Guide is too strict for me…

May 16, 2011

Franzk Franzk
Lab Rat
830 posts

I think the Google style guide documents the exact mistake a lot of companies make when they are prescribing the style this specifically. Programmers are usually free form thinkers. Putting a too rigid harness on that free form thinking lets developers focus on form rather than on functionality, and frankly, I’d rather have a bit of functionality. If you want to restrict coding rigidly to a certain standard, use a language that isn’t as free form as C++.

 Signature 

“Horse sense is the thing a horse has which keeps it from betting on people.”—W.C. Fields

http://www.catb.org/~esr/faqs/smart-questions.html

May 16, 2011

Peppy Peppy
Hobby Entomologist
389 posts

@Franzk: I totally agree with you.

Franzk wrote:
Programmers are usually free form thinkers.

I am too ;-)

May 16, 2011

leon.anavi leon.anavi
Mad Scientist
1047 posts

Volker, thanks for sharing! It is always good to know how leading companies work.

Andre wrote:
Personally, I really like the Qt convention that class names start with a capital, and method names with a lower case letter. That is different in the Google conventions.

Yes it is really nice, although I have to admit that I am still getting used to it :)

Franzk wrote:
I think the Google style guide documents the exact mistake a lot of companies make when they are prescribing the style this specifically. Programmers are usually free form thinkers. Putting a too rigid harness on that free form thinking lets developers focus on form rather than on functionality, and frankly, I’d rather have a bit of functionality. If you want to restrict coding rigidly to a certain standard, use a language that isn’t as free form as C++.

+1 :) Bull’s eye! :)

 Signature 

http://anavi.org/

May 16, 2011

Peppy Peppy
Hobby Entomologist
389 posts

I prefer Unix or BSD style, it’s not so strict as Google has…

Joke:

But the best thing that they wrote, was: http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml?showone=C++0x#C++0x
“ Decision: Use only C++0x libraries and language features that have been approved for use. Currently, no such features are approved. Features will be approved individually as appropriate.”
How can I use C++0x (as it Google said), if there is just specification out?? Think smarter and you’ll get nonsense of using this Google Style :D

May 17, 2011

Franzk Franzk
Lab Rat
830 posts

Preliminary implementations, which is why no libraries at all are approved. But one can hardly expect the trailing comma in enumerators to be a library function.

  1. enum HuuHaa {
  2.     Murk, // c++0x specific feature
  3. };

 Signature 

“Horse sense is the thing a horse has which keeps it from betting on people.”—W.C. Fields

http://www.catb.org/~esr/faqs/smart-questions.html

May 17, 2011

Alexander Kuchumov Alexander Kuchumov
Lab Rat
377 posts

I wonder, do trolls have analog cpplint.py?:)

May 19, 2011

situ117 situ117
Lab Rat
42 posts

http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Inline_Functions

Does Qt encourage inline functions inside the library which can be called from user code ? I guess it could cause binary incompatibilities if definition of inline function changes between library versions.

Page  
1

  ‹‹ displaying image using label in Qt4.7      What Every C/C++ Programmer Should Know About Undefined Behavior ››

You must log in to post a reply. Not a member yet? Register here!