3 ms·
2010-2017 Certainly at that time, creating your own templates was explicitly disallowed by the C++ style guide (ie readability requirements). The public style
by cletus 5y ago
2010-2017
Certainly at that time, creating your own templates was explicitly disallowed by the C++ style guide (ie readability requirements). The public style guide mentions template meta-programming specifically [1]:
> The techniques used in template metaprogramming are often obscure to anyone but language experts. Code that uses templates in complicated ways is often unreadable, and is hard to debug or maintain.
This certainly applied to Google3. Non-Google3 C++ code bases could and did have their own standards and style.
General note: templates were created but by library/framework teams who specialized in that. The way I like to put it, creating templates was a job for branch nodes not leaf nodes.
[1]: https://google.github.io/styleguide/cppguide.html#Template_metaprogramming https://google.github.io/styleguide/cppguide.html#Template_m...
- codeflo 5y agoI can’t contribute to the discussion about Google’s rules. I just want to mention that simple uses of templates for generic data structures are very different from template meta programming. I can see how a style guide might allow the former and ban the latter.
- pxx 5y agoThis restricts metaprogramming, not you putting "template <typename T>" in your code for a generic function. I don't know how you got such a weird read of the readability requirements; it is definitely not as strict as you put here (and I'm currently at Google and commonly write C++).
- UncleMeat 5y ago"Template meta-programming" and "templates" are very different. Further, the style guide says "avoid" but does not forbid it. Clang-Tidy doesn't throw up any warnings when using things like std::enable_if. My codebase overlaps with the majority of your tenure at Google. We are in google3. I do agree with the guidance that things like SFINAE should be avoided in general, but I believe you've way overstated the rigidity of the guidance.
- jeffbee 5y agoMy C++ readability changelist contained a template. I don't think this part of the style guide is what you thought it was.
- rpangrle 5y agoI'm a current Googler with C++ readability and I can confirm, you're absolutely allowed to write templates in "leaf node" projects and it's encouraged, especially in cases where templated code reduces error-prone boiler plate. Heck, there are whole Grow classes dedicated around learning how to use variadic templates.
- petters 5y agoCould you possibly be misremembering? I think creating e.g. template<F> F MyComputation(const F& x) would be allowed e.g. for supporting both float and double. It would also be required when using the Ceres optimization library.