@scottduckworth3299

I work at Google. This video barely scratches the surface of Google's C++ style guide. IMHO, the style guide is a wonderful thing, and makes C++ a pleasure to work with at Google.

Although your preferences may not agree with every little detail, the consistent application of the style guide across a massive codebase is highly valuable to everyone that will ever lay eyes on your code. There could easily be hundreds or thousands of engineers that interact with your code - interfacing with its API, extending it's functionality, debugging it, improving it's performance, etc. Every decision made by the style guide is one less thing all those engineers have to consider.

@chrisrockscode1202

One of my favorite videos on YouTube, I never even thought of looking at style guides. With a good amount of C++ under my belt I can totally see these guides being useful

@bitw1se

The multiple inheritance example is bad imo, because in that case you should actually let "Child" inherit from "Person", and not "Mother" and "Father". Inheritance is usually used to generalize something and abstract it away, like a "Table" is a type of "Furniture", but not a child is a mother and a father.

@ToCarlosHuevos

I never write any comments on YT but I really feel like doing it this time. I'm a C++ developer and it's my first job ever (same thing for my teammates), so we struggle with many of these details every day because I think it's quite hard to decide on your own which is the best practice. It's nice to know it's not only me and that it's a real deal out there to write good code in C++ (I also thought those many details of the language make it very powerful but difficult to manage correctly, but I thought it was just me being an inexperienced engineer). I really enjoyed this video, I would also like to see more C++ guidelines and stuff (obviously). Keep up the good work!

@astrahcat1212

I like reading 90s C++ projects, they released the source code for 3D Movie Maker recently and been reading through that. It delves you into another time, a 'simpler' time.

@decky1990

Aw man, two spaces??? I’m yet to try looking at code like that, but four has always looked better

@haxney

Great video!

A few things, from a Google engineer (not speaking for the whole company, of course).

1. We absolutely have tech debt. These things help reduce certain kinds of tech debt, but it still exists all over the place. We're not magical; we make bad choices which we're then stuck with.

2. The lexical code style goes beyond just tabs vs spaces. Our code review system will yell at you if the code isn't formatted according to whatever clang-format would produce. Our style guide for indentation, line breaks, etc, is just "run clang-format and use that". I don't always like the choices which clang-format makes, but it's infinitely better for everyone to use the same standard than for me to use a standard I like more, but for diffs to be larger due to whitespace changes.

3. An important part of the style guide boils down to "don't get clever with template metaprogramming." I've been writing C++ for about 3 years now, and as soon as things get beyond the most basic template usage, I'm lost. If you're relying on SFINAE, you should probably reach for a different solution. Same thing once you start dealing with rvalues and lvalues. There are some places where those features really do make sense, but for things like "call this service. If foo is greater than 25, set bar to true", you probably don't need that stuff.

@SevenRiderAirForce

Composition over inheritance and RAII (smart pointers) are the biggest lessons here. They drastically de-shittify your code.

@gvanvoor

2:27: make_unique< foo > will return a unique_ptr< foo >, not a foo (assuming the std namespace was dropped)

@9SMTM6

The worst Java code I've ever seen was part of (Googles) easier mediapipe API.

They had DEEP Inheritance, manually written getters and setters which contained a few surprises (like giving back properties that already had their own getters), made intensive use of method overloading and inherited methods including methods, and these methods often took parameters that were named in a way to imply they had a certain function, only to be thrown away/used in a different way, or they were actually set, but that didn't matter as at a later point in the lifecycle these values would be overwritten before doing anything.

Combine that with the need to also use the not easy and not well documented camera2 API (which they combined with some parts of CameraX) and that under all that Spagetti mess they used JNI to call C++ code that also wasn't particularly well documented, and I got nowhere but sure wasted a lot of time thinking I finally got to the target.

Honestly, while we're at this, LARGE swaths of the Android API require you to use implementation Inheritance, so thanks for forcing me to do the things you forbid your engineers to do Google.

Sorry for the rant, I'm still super salty from that experience. What they archived with mediapipe is remarkable, and it's nice they made it open source. But mediapipe did not keep it's promises (real time body tracking on IOT, pretty much every mobile - top models released after mediapipe - we tried didn't get over sustained 10 FPS, while being at best at a mean of 18 FPS), and the API was a nightmare and not at all flexible enough for our needs.

@silent_ptr

If Google doesn't like using exceptions cause of flow control stuff what do they prefer to use instead

@brendanhansknecht4650

Google doesnt allow exceptions because that is what they happened to pick years ago. They have debated enabling exceptions (they are generally more performant on the happy case for example), but mixing error returning code and exception code is a bad idea.

They say that if they were to start from scratch today, they probably would use exceptions instead of error returns.

@kuhluhOG

1:26 Yeah, that's the point of tab. That everyone who reads the code can configure it the way they want to be.
That way no matter who looks at the code, it will always be with the indentation the person feels comfortable with.
Especially 2 spaces are very little and becomes over the course of a work day quite eye straining (which btw is the reason why the Linux kernel defines 8 spaces..., tabs would still be better tho).
This is quite frankly the type of rule where I would configure my setup to convert 2 spaces into a tab when opening the file and on save convert a tab into 2 spaces...

@JeremyCoppin

My absolute favourite is working on a code base where a class inherits class templates that inherit other templates that inherit an interface. That's the ultimate in "FU figure this out" coding..

@theintjengineer

I don't agree with 100% of the guide (e.g. I can't have that 2-space indentation haha), but I loved the fact the video is about C++❤️
Please keep it up.
Greetings from Germany.

@vincenthilla3762

Great video and all...
just please don't build an inheritance relationship Child -> Mother, Father -> Person. Even with inheritance as a concept, that does not make sense. But especially in C++, inheritance means "is-a" and a Child is not always a Mother. Everything that would apply to Mother, would also be applicable to Child under C++.

@darkwoodmovies

The Google C++ style guide was my bible for a long time. It's incredible and makes C++ truly beautiful and easy. I miss my C++ days :)

@earlye

If I were writing this guide, I would say "use exceptions for all error conditions," "write exception safe code," "generally do not catch exceptions other than when you could conceivably recover," and "use RAII to avoid needing to catch exceptions."

It's a shame IMHO that exceptions seem to be losing favor industry-wide, as they really can make error handling easier and less error-prone. :sigh:

@yevgeniysimonov5906

It is true that in large projects using exceptions might be difficult to maintain, especially when there are many developers working on the same piece of code, however, they are good to have in situations where we receive completely unexpected data, corrupted data, or for validation reasons to bullet proof complex data pipelines.

@mdrehan493

The diamond problem in Inheritance,
Can be solved in C++. Because there is the concept of virtual ness which deals with that problem and prevent the base class to inherit multiple times