by hellofunk · 10y ago · 0 comments
It's at odds with almost all of it. Google's standards are C-with-classes based on compiler bugs circa 1999.
Despite their (misleading) marketing, Google is still just another enterprisey megacorp employing 30000 blub programmers. Expect the usual 'enterprise' failures.
Edit: It seems the standards have changed. It doesn't seem so bad now. They cant use exceptions but they can use some of boost cpp11 and templates. So maybe working at google ain't that bad.
Ouch! That must have hurt 'em. Of course the original meaning of "Blub" is "anything which isn't Lisp", especially C++ (as well as say Java.) But what the heck, it has a good sound to it.
Anyway, I think their C++ style guide isn't bad. As to "modern C++ style", let's wait for a few years, shall we? When the STL came out, auto_ptr and for_each(v.begin(), v.end(), FunctorFromHell()) were marketed as the way to go for a long while; then the usual suspects became a bit more silent. Now again, despite their being a smart for loop, for_each with a lambda (with its crazy capture lists and all) is supposedly considered at least as good as a for loop, and typically better. And you're supposed to use unique_ptr and what-not. Maybe a few years down the road things will look different again.
C++11/14 has a ton of weird shit you ought to keep in your mind on top of the weird shit in C++98/03 and many "enterprisey megacorps" seem to apply a restricted subset of C++ rather successfully.
Your definition of 'successfully' is vastly different from the Megacorp definition of 'successfully'. I interview C++ programmers _all the time_, and let me tell you: practically the only reason those restricted subsets of C++ exist is to allow bad programmers to work at Megacorp.
There are a lot of really unqualified C++ programmers in the world, and by far the biggest problem faced by Megacorp is employee churn, not code quality and not product deadlines.
The use of 'C++ subsets' solves the employee churn problem at the cost of code quality.
To me success includes being able to find (not frequently replace - I like working with the same people for many years - but find new ones in order to grow) developers that can contribute to the code base, and some of the best ones I know can't be bothered to learn much of C++. Go figure. Maybe you and I legitimately disagree because we work on different things, and maybe one of us is wrong.
Is C++14 a better language than C++98? It's hard to tell (I think it is - I think C++ is worse than C, but having gotten to C++98, perhaps it helps more than hurts to add all that other shit), but it's not an interesting question anyway because the upgrade is easy enough and it's worth it for most people for their specific reasons, so C++98 will die out.
But then it's not like Google aren't upgrading to the latest C++ standard, they're just doing it slowly AFAIK.
Lambdas would mean I could bin all those structs with bool operator()() for find_if that I have to litter my code with.
What do you mean by this?
- C style error codes
- minimal use of STL
- use of templates is frowned upon
- C style enums
This just of the top of my head, I would need to read it again to see if they changed anything.
I was recently reading the docs for a physics engine in c++ and they said that its initial implementation used std::vector in many places, but they instead implemented their own in later versions to accommodate maximum "portability and compatibility." I wonder what that means? Since the STL is included in C++ compilers and vector is always going to be there, why would they need to roll their own to make the engine either more portable or more compatible?
>use of templates is frowned upon
I wonder if this means the writing of templates, or using existing templates. If the latter, maybe like the STL their primary concern is compile times?
Basically, Google has an enormous code base. Stylistic decisions should have semantic weight, but since everybody has their own style, it becomes challenging to understand the reasoning behind certain choices. When you have a standard, it means that you can read into some of the stylistic decisions sprinkled throughout the code.
Take for example, the use of pointer arguments for passing the addresses of results. The justification is that using a pointer is explicit and unambiguous. Non-const references have value syntax but pointer semantics, which can be confusing. Yes, this is contrary to some of the core values behind C++ but Google felt that the improved readability was worth that dissonance.
Do Google enforce const pointers for arguments that define where to store results? If not, you could delete the pointer they pass you. A pointer does not always indicate who owns the data clearly.
Far better would be to return the values from the function (or std::move them out if you must) instead of using a parameter as a "dump your results here" flag.
Stroustrup encourages this (see 5.3.3 of C++ 4th edition where he says "I don’t consider returning results through arguments particularly elegant"). IMHO, it would be better to return a std::pair<bool, std::vector<myWonderfulType>> where bool indicates the success/failure of the function, with pair.second item being the results.
I imagine templates are frowned upon for the same reason -- too many moving parts. Otherwise they're perfectly fine to use in projects that have goals other than portably predictable performance.
Google around for Visual Studio 6 STL, and take into account the fact that most organizations don't upgrade right away, and you're looking at at least 2005 before you could rely on the STL cross-platform. Maybe much later.