All posts in "Expressive code"

Going Far into Polymorphic Helpers

Published May 29, 2020 - 0 Comments

When we saw How to Assign Derived Classes in C++, we came up with a technique involving runtime polymorphism mixed with CRTP. This allowed derived classes to benefit from a polymorphic assignment operator without implementing it themselves, thus reducing boilerplate code. But assignment is just a special case of a polymorphic function to implement on a […]

How to Assign Derived Classes in C++

Published May 22, 2020 - 0 Comments

A classical problem in object-oriented programming, and with polymorphism in general, is to handle multiple polymorphic objects at the same time. In other terms, multiple dispatch. An associated problem with object-oriented programming is that many languages, including C++, don’t implement multiple dispatch. One case comes up often: handling the behaviour of two objects of the […]

Runtime Polymorphism Without Objects or Virtual Functions

Published May 15, 2020 - 0 Comments

When thinking of polymorphism, and in particular of runtime polymorphism, the first thing that comes to mind is virtual functions. Virtual functions are very powerful, and fit for some use cases. But before using them, it’s a good thing to consider our exact need for polymorphism, and look around if there are other, more adapted […]

Evaluating user-defined logical expressions

Published May 8, 2020 - 0 Comments

This is a guest post by Marin Peko. Marin is a Software Engineer working at Cellusys, a company providing telecommunication solutions, and follower of Fluent C++. You can find him on LinkedIn and Github. Logical expressions are probably one of the most used concepts in computer science and certainly a large part of each code […]

Else Before If

Published April 24, 2020 - 0 Comments

Imagine yourself discovering a part of your codebase and, in the midst of your exploration, you’re coming across an if statement of an honourable stature, featuring an `if` branch, an `else if` branch, and an `else`. As you’re approaching it with a mix of suspicion and curiosity, the if statement presents you its foremost part: […]

An Online Source Code Control Flow Filter

Published April 10, 2020 - 0 Comments

Clean code guidelines recommend keeping functions short, because long functions are difficult to understand and maintain. However, there is legacy code out there were functions span across hundreds, or even thousands of lines. There is now way someone can keep so many lines of code in their mind. By scrolling through such a function, we […]

Implementing a Line Filter in C++

Published March 27, 2020 - 0 Comments

Filtering lines based on a certain pattern is a common task in the everyday life of a programmer. For example we saw in a recent post the technique taken from The Legacy Code Programmer’s Toolbox that consists in filtering code on control flow keywords in order to get an overview of its structure. We’re going to write a […]

How to Get the “Table of Contents” Of a Long Function

Published March 13, 2020 - 0 Comments
table of contents code function

Long functions are hard to understand, and to write expressive code we generally try to keep functions short enough to get an overview of what they’re doing. The exact threshold over which a function becomes too long has been debated and is not clear today (see Code Complete, section 7.4 for a discussion about this), […]

C++ Regex 101

Published February 28, 2020 - 0 Comments

Since C++11, the C++ standard library contains the <regex> header, that allows to compare string against regular expressions (regexes). This greatly simplifies the code when we need to perform such operations. The <regex> header comes with a lot of features, and it might not be easy to know where to start. The first time I used it, […]

1 4 5 6 7 8 20