Cpp - vanhoan310/tips GitHub Wiki

Need to USE/LEARN https://github.com/vanhoan310/CppCoreGuidelines/blob/master/CppCoreGuidelines.md

  • Constant correctness

  • Smart poiners

  • Rule of 5

  • Avoid memory leaks through use shared pointers to manage memory allocation and cleanup

  • Use the Resource Acquisition Is Initialization (RAII) idiom to manage resource cleanup - especially in the presence of exceptions

  • Avoid calling virtual functions in constructors

  • Employ minimalist coding techniques where possible - for example, declaring variables only when needed, scoping variables, and early-out design where possible.

  • Truly understand the exception handling in your code - both with regard to exceptions you throw, as well as ones thrown by classes you may be using indirectly. This is especially important in the presence of templates.

  • RAII, shared pointers and minimalist coding are of course not specific to C++, but they help avoid problems that do frequently crop up when developing in the language.

  • Some excellent books on this subject are:

  • Effective C++ - Scott Meyers

  • More Effective C++ - Scott Meyers

  • C++ Coding Standards - Sutter & Alexandrescu

  • C++ FAQs - Cline

Lessons

  1. Pointers, push_back vector with move https://stackoverflow.com/questions/2275076/is-stdvector-copying-the-objects-with-a-push-back
  2. Parallel OPENMP https://bisqwit.iki.fi/story/howto/openmp/#LoopDirectiveFor and more https://software.intel.com/en-us/articles/choosing-the-right-threading-framework
  3. Top 10 Most Common C++ Mistakes That Developers Make https://www.toptal.com/c-plus-plus/top-10-common-c-plus-plus-developer-mistakes
  4. When/why use pointers and dynamic allocation https://stackoverflow.com/questions/22146094/why-should-i-use-a-pointer-rather-than-the-object-itself
  5. Common mistakes https://www.quora.com/Which-common-mistakes-do-beginner-C-programmers-often-commit

Note

  1. return will make a copy. How to avoid it? https://stackoverflow.com/questions/395123/raii-and-smart-pointers-in-c
  2. When we should use pointers? https://stackoverflow.com/questions/22146094/why-should-i-use-a-pointer-rather-than-the-object-itself