Collecting the best C++ practices
Tags: discuss, productivity, cpp, community
Published: 2023-01-13 08:04:25

Reading our articles, you may wonder: why are they always talking about bad things? This code contains bug; there are code smells here; it's an antipattern — don't code like that\. So, would you help me to look on the bright side of C\+\+ programming? Feel free to leave comments 💬


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/93ysizd5ku4ihw56p88d.png)

Recently I came across a discussion on Reddit "[Good repos for beginners to browse that follow best modern C\+\+ practices \(including testing, static analysis etc\.\.\.\)](https://www.reddit.com/r/cpp/comments/z3i2ae/good_repos_for_beginners_to_browse_that_follow/)"\. The thread is not the longest one, but it's still quite interesting\. Then, an idea popped into my head — why don't I post a survey on Habr\.com? I did the same with terrible coding tips\.

By the way, the idea to write an article about [terrible coding tips](https://pvs-studio.com/en/blog/posts/cpp/0953/?utm_source=website&utm_medium=dev_to&utm_campaign=article&utm_content=Best_Cpp_Practices&utm_term=0953) is evolving\. Soon I plan to publish a book with 60 anti\-patterns in C\+\+\. [Subscribe](https://pvs-studio.com/en/subscribe/?utm_source=website&utm_medium=dev_to&utm_campaign=article&utm_content=Best_Cpp_Practices&utm_term=subscribe) to our monthly newsletter, if you don't want to miss the most interesting publications\.

So, the topic of terrible coding tips is covered :\)\. It's time to talk about good practices\!

I go first\. Then, I invite you to join me and write in the comments:

* what tools you recommend;
* what interesting and useful libraries you use;
* what projects are useful in learning C\+\+;
* what practices, coding standards you can advise;
* and so on\.

## Starters

1. [ModernCppStarter](https://github.com/TheLartians/ModernCppStarter)\. Kick\-start your C\+\+\! A template for modern C\+\+ projects using CMake, CI, code coverage, clang\-format, reproducible dependency management and much more\.
1. [gui\_starter\_template](https://github.com/cpp-best-practices/gui_starter_template)\. This is a C\+\+ Best Practices GitHub template for getting up and running with C\+\+ quickly\.

## Projects to learn C\+\+

Note to self\. If I write an article on the collected information later, I need to check these and other proposed projects with PVS\-Studio\. [Libraries are different, you know\.\.\.](https://pvs-studio.com/en/blog/posts/cpp/0762/?utm_source=website&utm_medium=dev_to&utm_campaign=article&utm_content=Best_Cpp_Practices&utm_term=0762) I don't want to recommend something potentially buggy as an example to follow\.

1. [Diligent Engine](https://github.com/DiligentGraphics/DiligentEngine)\. A Modern Cross\-Platform Low\-Level 3D Graphics Library and Rendering Framework Tweet\.
1. [JSON for Modern C\+\+](https://github.com/nlohmann/json)\. Intuitive syntax\. Trivial integration\. Serious testing\. Memory efficiency\. Speed\.
1. [Stroika](https://github.com/SophistSolutions/Stroika) is a modern, portable, thread\-savvy, C\+\+ application framework\. It makes writing high performance C\+\+ applications easier by providing safe, flexible, modular building blocks\.
1. [concurrencpp](https://github.com/David-Haim/concurrencpp)\. Modern concurrency for C\+\+\. Tasks, executors, timers and C\+\+20 coroutines to rule them all\.
1. [awesome\-hpp](https://github.com/p-ranav/awesome-hpp)\. A curated list of awesome header\-only C\+\+ libraries\.

## Speeding up the build

1. Here I invite you to read my colleague's article "[Speeding up the build of C and C\+\+ projects](https://pvs-studio.com/en/blog/posts/cpp/0549/?utm_source=website&utm_medium=dev_to&utm_campaign=article&utm_content=Best_Cpp_Practices&utm_term=0549)"\.
1. There are various [old](https://stackoverflow.com/questions/373142/what-techniques-can-be-used-to-speed-up-c-compilation-times) and [new](https://www.reddit.com/r/cpp/comments/hj66pd/c_is_too_slow_to_compile_can_you_share_all_your/) discussions on this topic\. I am excited to learn about new, interesting things on this topic from you\. Thanks in advance\.

## Coding standards and style guides

1. The [C\+\+ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines) are a collaborative effort led by Bjarne Stroustrup, much like the C\+\+ language itself\. They are the result of many person\-years of discussion and design across a number of organizations\.
1. [Collaborative Collection of C\+\+ Best Practices](https://github.com/cpp-best-practices/cppbestpractices)\. This online resource is part of Jason Turner's collection of C\+\+ Best Practices resources\. By the way, since I mentioned Jason, here's the link to his [C\+\+ Weakly](https://www.youtube.com/channel/UCxHAlbZQNFU2LgEtiqd2Maw) channel\.
1. [Google C\+\+ Style Guide](https://google.github.io/styleguide/cppguide.html)\. The goal of this guide is to manage this complexity by describing in detail the dos and don'ts of writing C\+\+ code\. These rules exist to keep the code base manageable while still allowing coders to use C\+\+ language features productively\.

## Dynamic code analysis

1. [AddressSanitizer](https://github.com/google/sanitizers/wiki/AddressSanitizer) finds memory errors\.
1. [LeakSanitizer](https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer) searches for memory leaks\.
1. [ThreadSanitizer](https://github.com/google/sanitizers/wiki/ThreadSanitizerCppManual) detects data races and deadlocks\.
1. [MemorySanitizer](https://github.com/google/sanitizers/wiki/MemorySanitizer) looks for uninitialized memory\.
1. [HWASAN](https://clang.llvm.org/docs/HardwareAssistedAddressSanitizerDesign.html), or Hardware\-assisted AddressSanitizer, a new variant of AddressSanitizer that uses less memory\.
1. [UBSan](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html) finds undefined behavior in a program\.

## Static code analyzers

1. Here I will play dumb and mention only our PVS\-Studio\. Well, why not? It's a wonderful and [powerful static code analyzer](https://pvs-studio.com/en/blog/posts/0908/?utm_source=website&utm_medium=dev_to&utm_campaign=article&utm_content=Best_Cpp_Practices&utm_term=0908)\. The tool helps find lots of errors and potential vulnerabilities even at the stage of writing C\+\+ code\.
2. TODO\. I'm also excited to hear about your successful experiences of using other static code analyzers\.

## Books and other references

1. I always recommend everyone to read Code Complete by Steve McConnell \(ISBN 0\-7356\-1967\-0\)\.
2. [C\+\+ Best Practices \(2019\)](https://rigtorp.se/cpp-best-practices/)\.
3. [The Ultimate Question of Programming, Refactoring, and Everything](https://pvs-studio.com/en/blog/posts/cpp/0391/?utm_source=website&utm_medium=dev_to&utm_campaign=article&utm_content=Best_Cpp_Practices&utm_term=0391)\.
4. [C\+\+ Coding Standards: 101 Rules, Guidelines, and Best Practices](http://micro-os-plus.github.io/develop/sutter-101/)\.
5.  Scott Meyers\. Effective C\+\+: 55 Specific Ways to Improve Your Programs and Designs \(3rd edition\)\.
6.  Scott Meyers\. Effective Modern C\+\+: 42 Specific Ways to Improve Your Use of C\+\+11 and C\+\+14"\.

## Now, it's your turn 💥

Please share everything that you consider useful to C\+\+ programmers\!