This article is NWH, standing for Not Written Here. The concept of NWH is inspired from the NIH (Not Invented Here) syndrome which consists in refraining from using existing code from outside the company and reinventing the wheel every time. Just like it is good practice to look out for solutions developed elsewhere, we’re going […]
C++11 added two keywords that allow to better express your intentions with what you want to do with virtual functions: override and final. They allow to express your intentions both to fellow humans reading your code as well as to the compiler. However, as we will see, the intention of override is super useful, but the intention of final… […]
In C++, most STL algorithms can use one function to perform their job on a collection. For example, to extract all the even numbers from a collection, we can write code like this: auto const numbers = std::vector<int>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; auto results = std::vector<int>{}; std::copy_if(begin(numbers), end(numbers), back_inserter(results), isMultipleOf2); Assuming […]
Interrupting a sequence of operations when one of them fails is a common problem in computer programming. There are plenty of elaborate ways to code that, ranging from exceptions to monads to static exceptions. One of the techniques to stop such a sequence of operations that is not so sophisticated, but that can be found […]
Every piece of code we write is unique, or pretty much. However, there are things that are common in a lot of code, even across various codebases, and even across various languages: the physical shape that code has. Beyond the mere visual aspect of code, the shape of a piece of code can carry information […]
Have you ever felt that the code you write in if statements doesn’t look as natural as the specification expresses them? For example, if the specification looked like this: “if any of x, y, or z is less than 100, then perform such and such action”, a common way to express this condition in C++ […]
This article is NWH, standing for Not Written Here. The concept of NWH is inspired from the NIH (Not Invented Here) syndrome which consists in refraining from using existing code from outside the company and reinventing the wheel every time. Just like it is good practice to look out for solutions developed elsewhere, we’re going […]
Sometimes, the simplest requirements can be tricky to code in an expressive manner. For example, I recently had to code up some logic to determine if a transaction consisted in paying money or receiving money. To determine this, the transaction has two relevant parameters: the price of the transaction, that can be positive or negative. […]
Just because we can provide an interface doesn’t mean that we should. At least this is one of the takeaways that I got from from Howard Hinnant’s opening keynote at Meeting C++ 2019. In this impressive keynote, Howard made a presentation about <chrono> and the host of features it brings in C++20. But beyond showing us […]
There is just too much to know to master programming in C++. I’m not talking about putting together small programs in C++. I’m talking about mastering the skills that are required to create industry-level software. When it comes to the code itself, you need to master at least the following things: the core concepts of […]