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 π¬
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...)". 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 is evolving. Soon I plan to publish a book with 60 anti-patterns in C++. 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
- ModernCppStarter. Kick-start your C++! A template for modern C++ projects using CMake, CI, code coverage, clang-format, reproducible dependency management and much more.
- 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... I don't want to recommend something potentially buggy as an example to follow.
- Diligent Engine. A Modern Cross-Platform Low-Level 3D Graphics Library and Rendering Framework Tweet.
- JSON for Modern C++. Intuitive syntax. Trivial integration. Serious testing. Memory efficiency. Speed.
- 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.
- concurrencpp. Modern concurrency for C++. Tasks, executors, timers and C++20 coroutines to rule them all.
- awesome-hpp. A curated list of awesome header-only C++ libraries.
Speeding up the build
- Here I invite you to read my colleague's article "Speeding up the build of C and C++ projects".
- There are various old and new 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
- The C++ Core Guidelines 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.
- Collaborative Collection of C++ Best Practices. 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 channel.
- Google C++ Style Guide. 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
- AddressSanitizer finds memory errors.
- LeakSanitizer searches for memory leaks.
- ThreadSanitizer detects data races and deadlocks.
- MemorySanitizer looks for uninitialized memory.
- HWASAN, or Hardware-assisted AddressSanitizer, a new variant of AddressSanitizer that uses less memory.
- UBSan finds undefined behavior in a program.
Static code analyzers
- Here I will play dumb and mention only our PVS-Studio. Well, why not? It's a wonderful and powerful static code analyzer. The tool helps find lots of errors and potential vulnerabilities even at the stage of writing C++ code.
- TODO. I'm also excited to hear about your successful experiences of using other static code analyzers.
Books and other references
- I always recommend everyone to read Code Complete by Steve McConnell (ISBN 0-7356-1967-0).
- C++ Best Practices (2019).
- The Ultimate Question of Programming, Refactoring, and Everything.
- C++ Coding Standards: 101 Rules, Guidelines, and Best Practices.
- Scott Meyers. Effective C++: 55 Specific Ways to Improve Your Programs and Designs (3rd edition).
- 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!
Top comments (1)
I would recommend keeping YouTube in mind. There's always something you'll find interesting, like conference talks, podcasts, and tutorials. Hereβs my personal list of favorite channels:
One more thing, since you mentioned static and dynamic code analysis, let's not forget about unit testing as well :) There are more than enough libraries for this, but I use the following ones: