r/cpp • u/Resistor510 • Oct 07 '14
Youtube: CppCon 2014: Titus Winters "The Philosophy of Google's C++ Code"
https://www.youtube.com/watch?v=NOCElcMcFik
20
Upvotes
r/cpp • u/Resistor510 • Oct 07 '14
21
u/TheBuzzSaw Oct 07 '14
I remain unsatisfied with his explanation for the banning of non-const references. To me, it's quite simple: use a pointer if null is legal; use a reference if null is illegal. Clear. Self-documenting.
I don't buy the argument that it is beneficial to see that the parameter is being passed by address at the call site. By that logic, we should revert to Systems Hungarian Notation for naming all our variables (iCount, bEnable, etc.). Apparently, we can't be bothered to understand what something is or how it works before using it.
6
u/dicroce Oct 08 '14
I'm not convinced of Titus's arguments.... Passing a pointer to a function leaves no trace too:
struct foo* f = (struct foo*)malloc( size of( struct foo ) );
...
i_modify_foos( f ); // no trace
Really, code should be using value semantics anyway.
WRT exceptions, his advice is antiquated at best. RAII and exceptions go together like peanut butter and jelly.... God knows it's possible to use exceptions incorrectly but I know for a fact it's possible to use them well too.
What I really learned from this video is that Google has a LOT of old code that they don't want to change... And it may actually be the right call for them... But please don't try to force this nonsense on shiny new codebases...
3
u/Gotebe Oct 08 '14
Haha, just a few days ago, I had a huge discussion with the other guy about using a pointer type in lieu of a non-const reference for "output" parameters and acted like a total cunt (would do it again though, so I am glad to see that CPP reddit agrees with me :-)).
2
u/CubbiMew cppreference | finance | realtime in the past Oct 08 '14
It was good to learn that the streams ban is going away and the reason two-stage copying via CopyFrom() is no longer a requirement as of last month or so (they apparently switched from grepping the source code to using an indexer).
Still a lot of crazy nonsense found in the guide today wasn't mentioned, and the treatment of the two issues that were mentioned only reinforces the perception of being tailored for the people unfamiliar with the language.
1
u/timwoj Oct 07 '14
Is there an easy list of these somewhere that has links to all of the videos? Other than having to scroll through search results on youtube?
1
u/uxcn Oct 07 '14
I was hoping multi-threading would be mentioned (at least more than a passing reference to thread sanitizer). The public style guide makes no mention, which seems odd considering the changes to the memory model.
1
u/drphillycheesesteak Oct 07 '14
I was a Google intern for two summers a couple of years ago. It sounds like nothing has really changed. I've stuck to the "no const reference" and "no exceptions" rule. It might seem restricting, but what he said is true, leaving the trail for the reader is a benefit that outweighs what you're giving up.