Title: Theory / Unimportant / CS / Programming / C++ / Manual / Norm / Google
Tags: seen_description
On every note of this deck, unless a note says otherwise:
Page: https://google.github.io/styleguide/cppguide.html

Question: In which case can .cc files be without .h files
Answer: unit test
Answer2: file with a single main function

Question: Constraints on .h file
Answer: Should be self contained (compile on their own)
Answer2: Have header guards

Question: Where to put template definition
Answer: with their declarations

Extension: .inc
Description: File to be included in middle of other file
Other fields (not shown on cards):
Page: https://google.github.io/styleguide/cppguide.html

Question: Where to put inline function definition
Answer: with their declarations

Instruction: #ifndef <PROJECT>_<PATH>_<FILE>_H_
#define <PROJECT>_<PATH>_<FILE>_H_
 ...
#endif // <PROJECT>_<PATH>_<FILE>_H_
Page: https://google.github.io/styleguide/cppguide.html
Effect: Ensure this file is included at most once, and does not forbid inclusion of other file
Language: C++
Name: Header guard

Name: Forward declaration
Definition: A declaration of a class, function, or template without an associated definition.
Page: https://google.github.io/styleguide/cppguide.html
Context: C++

Question: What are the pro of forward declaration
Answer: Forward declarations can save compile time, as #includes force the compiler to open more files and process more input.
Answer2: Forward declaration allow for mutually recursive definition
Answer3: Forward declarations can save on unnecessary recompilation. #includes can force your code to be recompiled more often, due to unrelated changes in the header.

Question: What are the cons of forward declaration
Answer: Forward declarations can hide a dependency, allowing user code to skip necessary recompilation when headers change.
Answer2: A forward declaration may be broken by subsequent changes to the library. Forward declarations of functions and templates can prevent the header owners from making otherwise-compatible changes to their APIs, such as widening a parameter type, adding a template parameter with a default value, or migrating to a new namespace.
Answer3: Forward declaring symbols from namespace std:: yields undefined behavior.
Answer4: Forward declaring multiple symbols from a header can be more verbose than simply #includeing the header.
Answer5: Structuring code to enable forward declarations (e.g. using pointer members instead of object members) can make the code slower and more complex.
Answer6: It can be difficult to determine whether a forward declaration or a full #include is needed. Replacing an #include with a forward declaration can silently change the meaning of code:
      // b.h:
      struct B {};
      struct D : B {};
      // good_user.cc:
      #include "b.h"
      void f(B*);
      void f(void*);
      void test(D* x) { f(x); }  // calls f(B*)
If the #include was replaced with forward decls for B and D test() would call f(void*).

Question: When it is okay to define inline functions ?
Answer: When they are small. 10 lines or fewer
Context: C++ style

Question: Pros of inline function
Answer: More efficient object code for small functions

Question: Cons of inline function
Answer: Augment code size, and bigger code runs smaller on modern processor

Question: When is it okay to inline a function with a loop/switch
Answer: if in the comon case, loop/switch is never executed

Question: What kind of function not to inline (usually)
Answer: Recursive
Answer2: destructor

Question: In which order to write header inclusion
Answer: All groups separated by an empty line
Answer2: In alphabetical order in a group
Answer3: Related header (header of current file)
Answer4: C system headers
Answer5: c++ std lib headers
Answer6: Other lib headers
Answer7: project's header

Question: When can you avoid importing header defining a symbol we use ?
Answer: Forward declaration
Context: C++
Answer2: If we include a header which make it clear that it expect to always include the definition from another header

Question: Which version of C++ google use
Answer: C++17
Context: C++

Question: What is the pro of namespace use
Answer: Ensure that there is no confusion, even if a function name is used in two different projects
Context: C++

Question: What is the cons of namespace use
Answer: clutter the code, by making function name far longer
Context: C++

Question: When is it okay to use "using namespace foo"
Answer: never, because it pollute the namespace
Context: C++

Question: When is it okay to use namespace alias
Answer: only for internal namespace; because otherwise it becomes part of the public API exported by that file
Context: C++

Question: What are syntactic rules for namespace
Answer: No indentation
Context: C++
Answer2: Ends with comment indicating the namespace ended

Question: What to do with definitions that are not referenced outside of their files
Answer: either make them static
Context: C++
Answer2: or use unnamed namespace

Question: Static method of a class should generally
Answer: be closely related to instances of
Context: C++
Answer2: be closely related to the class or the class's static data.

Question: What are rules related to variable creation
Answer: Declare them in the innermost scope as possible
Context: C++, Google style guide
Answer2: If it's an object type, declare it outside of loop if possible, so that it's initialized only once
Answer3: put the declaration as close as possible to initialization

Question: When can we use static storage duration ?
Answer: When it is trivially destructible
Context: C++ styleguide

Question: Why does C++ does not deal with multiple address space and process
Answer: It assumes it'll be used in an environment where a scripting language/OS can deal with starting multiple process and let them communicate
Page: 16
Chapter: 1
Section: 2.4

Question: How to do mutually recursive definition in C++?
Answer: Use forward declaration.

Question: How to save compilation time, while you work on one file that recursively must includes a huge number of other files
Answer: Use forward-declaration to declare the actually imported functions. This will avoid the opening all the related files