F2 : Rename
F12 : Go to definition
ALT + O : Switch between .h and .cpp
Clear commit : [part of the code] Add/Fix/Update thing
Use variables or functions to split complicated statements (in 'if' statement for example)
Prefer the stack
When to use the heap : for varying-size objects, for big objects or for polymorphisme
Better encapsulation (can only use the public interface of the class)
Easy to reuse, minimal dependencies
Prefer struct over class if no invariants to enforce
Single Responsability Principle : not mix concerns inside a single class
No private methods : use free functions instead
Public methods only to access private members
Designated initializers : we can initialize an instance by naming its members
Ex : .initial_width = 500
Code duplication doesn't mean textual duplication
enum class : type checking
"using enum nameOfEnum" : skip enum name in all switch cases
Static polymorphism (compile time) through templates
Dynamic polymorphism (runtime) - std::variant - std::function
Good use for inheritance : interfaces
Carry specific meaning through its name -> concrete representation to concepts, physical units, coordinate spaces...
Prevent logic errors and make APIs harder to misuse
Add libraries with CMake :
add_subdirectory(libname) target_link_libraries(${PROJECT_NAME} PRIVATE libname)
for (/*const*/ auto& element : v) { // ... }Guarantees that we are not modifying the index in the body of the loop
To represent an object that might be empty (std::nullopt)
Only store an information once
Inline documentation
Doxygen
debugging tool
static_assert happens at compile time and assert at runtime
to use when it's more readable (not just to save some typing)
to store a function
C++ #include <functional>
Fork and make a dedicated branch
Alternative to enums : list of possible states + contain data