Jonathan Boccara's blog

The Interesting Evolution of std::equal_range

Published January 10, 2022 - 0 Comments

The good old std::equal_range STL algorithm, which has been in the STL since C++98, has evolved along with the versions of C++. Starting from a poor interface and now a much better one, its story is an interesting example of how to improve the abstraction of an interface. (Good?) old C++98 equal_range The first version of […]

A Simple Habit to Avoid Complex Names and Typos in Code

Published December 27, 2021 - 0 Comments

Don’t you find it a little unsettling when you encounter a typo in code? std::unordered_map<int, Value> MyClass::getInedxedValues() const { // … } And the code looks even more careless when that typo is repeated several times across the codebase, in code that depends on the butchered symbol: auto const table1 = x.getInedxedValues(); auto const table2 […]

The Evolutions of Lambdas in C++14, C++17 and C++20

Published December 13, 2021 - 0 Comments

Lambdas are one of the most popular features of Modern C++. Since their introduction in C++11, they’ve become ubiquitous in C++ code. But since their appearance in C++11, they have evolved and gained significant features. Some of those features help write more expressive code, and since using lambdas is so common now, it is worth […]

How to Quickly Understand the Code of a Function

Published November 30, 2021 - 0 Comments

A lot of people struggle with legacy code because it’s hard to understand. It’s not expressive. One way to reduce the gap between code writer and code reader so that they reach an understanding is to write expressive code indeed. In all cases, you need to be able to read code quickly. The more expressive, […]

Design Patterns VS Design Principles: Template Method

Published November 17, 2021 - 0 Comments

In today’s episode of “Design Pattens VS Design Principles” series, we relate the Template Method design patterns to more general design principles. We’re showing how it relates to the Polymorphism design principle. The GoF Meets the GRASP If you’re just joining us in the series, here is what it’s about: we’re going over each of the […]

Strong Types for Safe Indexing in Collections – Part 1

Published October 31, 2021 - 0 Comments

Strong types make code safer and more expressive by using the type system to identify individual objects. For example, to instantiate a class Rectangle with a certain width and height, we could write this: Rectangle myRectangle{4, 5}; But then it isn’t clear for a reader of the code which of the two parameters is the […]

A Recap on User Defined Literals

Published October 8, 2021 - 0 Comments

User defined literals were introduced in C++11, evolved in C++14 and C++17, and are a nice way to write more expressive code. The general idea behind user defined literals is that they allow to write a value and tack on a term describing what this value represents. For example: auto const quantity = 42_bottles_of_water; In […]