7 Top Tips for Debugging C++--Greg Law

How do you do it?

7 Top Tips for Debugging C++

by Greg Law

From the article:

Brian Kernighan famously said, “Everyone knows that debugging is twice as hard as writing a program in the first place. So if you’re as clever as you can be when you write it, how will you ever debug it?”. For me, this doesn’t just mean “keep it simple.” It also means debugging is central to programming – you cannot be a great programmer without being great at debugging. Hopefully, my favorite C++ debugging tips will help you be as clever and productive debugging your code as you are writing it in the first place...

Decent concepts--Andrzej KrzemieĊ„ski

Are you using concepts?

Decent concepts

by Andrzej Krzemieński

From the article:

Last year I published two posts on writing concepts:

  1. Concept Archetypes,
  2. Semantic requirements in concepts.

Having had some time to reflect upon these posts, I now realize that the model presented in them is not complete. In this post I want to give a more coherent view of concepts...

A list of bad practices commonly seen in industrial projects-- Thomas Lourseyre

Are you in such an environement?

A list of bad practices commonly seen in industrial projects

by Thomas Lourseyre

From the article:

If you ever worked in a company-size software project (with numerous developers), there is a good chance that the codebase was, at least, pretty messy.

In these days, most industrial C++ developers are not experts. You will often work with developers with a Java or Python background, people who just learnt C++ at school and don’t really care that much about the language and old developers who code in “C with classes” instead of C++.

Having worked on a few industrial projects myself, I realized there are some recurring patterns and bad practices. If you happen to teach your coworkers to avoid these bad practices, you will all take a huge step toward a beautiful codebase and it will be beneficial to you, your coworkers and your project.

Here is a non-exhaustive list of these common bad practices...

Quick Q: Overload resolution between object, rvalue reference, const reference

Quick A: the better match is picked, and an error generated if there none.

Recently on SO:

Overload resolution between object, rvalue reference, const reference

As there is only one parameter, the rule is that one of the three viable parameter initializations of that parameter must be a better match than both the other two. When two initializations are compared, either one is better than the other, or neither is better (they are indistinguishable).

Without special rules about direct reference binding, all three initializations mentioned would be indistinguishable (in all three comparisons)...

GotW #102 Solution: Assertions and "UB" -- Herb Sutter

Solution just posted:

GotW #102 Solution: Assertions and "UB"

by Herb Sutter

From the article:

Now that we have considered assertions, postconditions, and preconditions in GotWs #97-101, let’s pause and reflect: To what extent does a failed contract imply "UB"... either the Hidden Dragon of Undefined Behavior, or the Crouching Tiger of Unspecified Behavior?

PVS-Studio Team: Switching to Clang Improved PVS-Studio C++ Analyzer's Performance

Although the project's preparation took a while, we were satisfied that the analyzer's performance grew by over 10%. We will use Clang to build future releases of PVS-Studio for Windows.

PVS-Studio Team: Switching to Clang Improved PVS-Studio C++ Analyzer's Performance

by Alexey Govorov and Sergey Larin

From the article:

From the earliest days, we used MSVC to compile the PVS-Studio C++ analyzer for Windows - then, in 2006, known as Viva64, version 1.00. With new releases, the analyzer's C++ core learned to work on Linux and macOS, and we modified the project's structure to support CMake. However, we kept using the MSVC compiler to build the analyzer's version for Windows. Then, in 2019, on April 29th, Visual Studio developers announced they had included the LLVM utilities and Clang compiler in the IDE.

 

How to Insert Several Elements in a Vector (With No Memory Errors)--Jonathan Boccara

How do you do it?

How to Insert Several Elements in a Vector (With No Memory Errors)

by Jonathan Boccara

From the article:

Inserting elements in a vector sounds like the most basic use case we can think of when it comes to using collections in C++.

Nevertheless, this is a complex topic in itself, because std::vector offers various ways to insert several elements. Choosing the most appropriate depending on your exact use case allows to write more expressive code. And misusing the interface of std::vector can lead to memory errors.

Let’s navigate the various ways to insert several elements in a vector in a safe way, so that you can choose the one that fits best for your code...