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 […]
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 […]
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 […]
In this series of articles on design patterns and design principles, we analyse how the 23 GoF design patterns relate to the 9 GRASP design principles. In a previous article, we classified the GRASP patterns like this (excluding “Managing complexity”): The study we perform in this series is helpful to understand better both the GoF […]
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 […]
In our objective to understand how the GoF design patterns relate to the GRASP design principles, we’re going to analyse 3 more Behavioural patterns today: Iterator, Mediator and Memento. Summary of the previous episodes As a reminder, the GRASP principles are a set of 9 design principles that help take design decisions about where to […]
Implementing comparison operators in C++ is easier said than done. Indeed, for most types, if we could talk to the compiler we would say something like: “to order them, use a lexicographical order on their members”. But when it comes to writing the corresponding code, things get more complicated. However, a classical technique using std::tuple makes […]
More than an exact science, designing our code is a craft (there is even a branch of software development that is called software craftsmanship). To guide us through this craft of designing our code we have guidelines that have been accumulated over the ages (or rather, decades) by software developers. 23 of them have been […]
By upgrading a compiler to C++17, a certain piece of code that looked reasonable stopped compiling. This code doesn’t use any deprecated feature such as std::auto_ptr or std::bind1st that were removed in C++ 17, but it stopped compiling nonetheless. Understanding this compile error will let us better understand a new feature of C++17: extended aggregate initialisation. The […]
Functions should take their inputs as parameters and produce outputs with their return types. This is the basics of functions interface design. This makes functions easier to understand just by looking at their prototype. It makes functions functional. But C++ only allows to return one value out of a function. What if we’d like to […]