Jonathan Boccara's blog

Minor, Major and Overarching Design Principles

Published July 1, 2021 - 0 Comments

Design principles are guidelines about how to organize and structure our code to make it manageable. They come through experience, in the general sense of the word. It can be one individual’s own trial and errors that makes them realize what options make code more simple. But in the more general sense, design principles stem […]

GRASP: 9 Must-Know Design Principles for Code

Published June 23, 2021 - 0 Comments

In order to write code that is understandable, maintainable and that stands the test of time, one of the crucial skills that we all need to have is design. What does code design mean? In my definition, doing code design means deciding which class (or more generally which component) is in charge of which responsibility. […]

5 Tips to Find Your Way Around A Legacy Codebase

Published June 15, 2021 - 0 Comments
understand legacy code

Have you ever struggled to understand a codebase that was bigger than you? Most of us go through this experience more or less often in our career, and this is not a simple thing to do. Chances are you’re in this situation right now. During one occurence of the Software Craftsmanship meetup somebody was asking for advice […]

The Subtle Dangers of Temporaries in for Loops

Published May 22, 2021 - 0 Comments

Even though very convenient to write concise code, temporaries are an endless source of bugs in C++. Are we allowed to use a temporary in a range based for loop? Consider the following code: std::vector<int> create_range() { return {1, 2, 3, 4, 5}; } int main() { for (auto const& value : create_range()) { std::cout […]

A Default Value to Dereference Null Pointers

Published May 14, 2021 - 0 Comments

With C++17, modern C++ has acquired a nullable object: std::optional. optional has a pretty rich interface, in particular when it comes to handling null optionals. On the other hand, the oldest nullable type in C++, pointers, doesn’t have any helper to make the handling of its nullity more expressive. Let’s see what we can do […]

Find with Custom Returns

Published May 7, 2021 - 0 Comments

Some STL algorithms have a default behaviour and also accept a custom value in order to have a custom behaviour. For example, std::sort orders the elements of a collection based on comparisons with operator< by default, but it also accepts a custom function to perform comparisons: std::sort(begin(v), end(v), std::greater{}); // sorts v in descending order This is the […]

How to Implement std::conjunction and std::disjunction in C++11

Published April 30, 2021 - 0 Comments
conjunction

Among the many features that C++17 introduced, the standard library got std::conjunction and its brother (or is it a sister?) std::disjunction. std::conjunction allows to perform a logical AND on a variadic pack of boolean values, and std::disjunction a logical OR: std::conjunction<Bs…>::value // is true if all Bs… are true, false otherwise std::disjunction<Bs…>::value // is true if at least one […]

Make Bad Code Look Bad

Published April 23, 2021 - 0 Comments

If you’re working with legacy code, chances are some of the areas of code you’re in charge of have a design that is less than ideal. But if you’ve been working with it for a while, you may be able to navigate this code with ease, and maybe you don’t even see its little weirdnesses […]