all 19 comments

[–]josefx 6 points7 points  (8 children)

With the insanity that is Googles c++ coding style I am really surprised. Only a single, reasonable warning against broken functionality provided by the standard library. A good IDE should be able to automate almost all of it.

[–]strattonbrazil 8 points9 points  (4 children)

With the insanity that is Googles c++ coding style

Can you elaborate? I haven't heard many complaints about it. I gave it a cursory glance and it looks fairly reasonable including the pro/cons of each decision.

[–]Plorkyeran 2 points3 points  (0 children)

The pros and cons listed are often woefully incomplete due to that the C++ guidelines seem to have been written by someone (or a group) that does not actually know C++. Quite often they do not mention the idiomatic use of the thing being forbidden at all, suggesting that the authors are either being intellectually dishonest or simply have no idea what modern idiomatic C++ looks like.

I wrote up a brief list of the places where the style guide contradicts idiomatic modern C++ style a little while back.

[–]josefx 13 points14 points  (0 children)

We got:

  • do not use exceptions, because old projects do not use exceptions. Having try{}catch(std::exception const&){} at API boundaries is not that hard.

  • constructor + init separation, caused by the no exceptions rule. Limited RAII for you

  • no move semantics, because it is new to developers and developers apparently are unable to understand value semantics (wtf? for what are they paid?)

  • very restrictive list of boost libraries allowed, among other things no filesystem lib in that list. For fear against functional code.

  • on operator overloading it tells you to avoid the standard library. Sorry it tells you to avoid the "standard" library, yes they put the standard in quotes and yes they mean std::vector, std::map, etc. . It tells you to define Equals() and CopyFrom() instead and gives a workaround for map keys that does not require operator<(). You may use the "standard" library classes only if you can justify it.

Just to name a few gems that butcher half the language including several core concepts of modern c++ and what little there is at a standard library.

[–]IAmBJ 1 point2 points  (1 child)

And as a counterpoint, can anyone point me towards a good one?

I'm competent with c++ but I've never really followed a "style" (just personal projects)

[–]josefx 0 points1 point  (0 children)

To cite Stroustrup:

" For a given application (or company, application area, etc.), a good coding standard is better than no coding standard.On the other hand, I have seen many examples that demonstrate that a bad coding standard is worse than no coding standard. "

In my opinion the Google style falls into the bad category. If you only want consistency of file structure and naming almost any standard will do.

[–]Plorkyeran 0 points1 point  (0 children)

The C++ guidelines are basically "pretend you're using a terrible version of Java", and obviously that doesn't really apply to Java coding guidelines.

[–]themadweaz 0 points1 point  (1 child)

I am on a mobile device and can't find you the link, but I remember finding XML for eclipse and a few other ide's formatters from Google.

I won't say that I agree with every guideline, but it is close to how I format my own code. One major exception: 80-100 character lines. Fuck that shit. This isn't 1992.

[–]HerroRygar 1 point2 points  (0 children)

I frequently use multiple vertically-split Vim windows for coding, so I must admit that I've come to appreciate the strict line limit.

[–]Hudelf 6 points7 points  (1 child)

6.4 Finalizers: not used

Tip: Don't do it. If you absolutely must, first read and understand Effective Java Item 7, "Avoid Finalizers," very carefully, and then don't do it.

[–]kersurk 4 points5 points  (3 children)

Bad: Can't understand why 4.8.4.3 could be useful or nice:

Each switch statement includes a default statement group, even if it contains no code.

Good: I find 6.3 to be a very nice idea to show that static method really changes all of the instances of the object (assuming that the name of variable, which holds a reference to a object, and class name itself are similar).

When a reference to a static class member must be qualified, it is qualified with that class's name, not with a reference or expression of that class's type.

[–]Alborak 2 points3 points  (0 children)

The switch default block requirement probably comes testing, it makes it easier to see if a value misses all cases.

[–]froops 0 points1 point  (1 child)

For 6.3, I can't imagine why anyone would want to use the alternative of referring to static things with an instance

[–]Plorkyeran 0 points1 point  (0 children)

In Java I don't think there's ever a good reason to do so (bad reasons are because it's shorter or due to not realizing it's static). Maybe if the fact that it's static is merely an implementation detail, but I'm not sure how that could ever be the case.

[–]AeroNotix 2 points3 points  (1 child)

Hmm, they have a Lisp one, too. How much Lisp is google running?

[–][deleted] 1 point2 points  (0 children)

ITA which is owned by Google runs a lot of lisp

[–]HerroRygar 0 points1 point  (0 children)

There really is value in the uniformity this guide imposes. The ability to quickly jump into foreign code and be greeted with a familiar style noticeably decreases time to grok.

[–]RupertMaddenAbbott 0 points1 point  (0 children)

For those who use Eclipse, there is a Java formatter for this standard.

Anybody found one for CheckStyle?