Jonathan Boccara's blog

How to Design Early Returns in C++ (Based on Procedural Programming)

Published August 24, 2018 - 12 Comments

Travelling back from ACCU conference a couple of weeks ago, one of the insights that I’ve brought back with me is from Kevlin Henney’s talk Procedural Programming: It’s Back? It Never Went Away. It’s surprisingly simple but surprisingly insightful, and it has to do with early return statements. Early return statements are controversial in the programming […]

Integrating Mocking With C++ Default Parameters

Published August 21, 2018 - 5 Comments
testable expressive C++

When we put a piece of code into a unit test, sometimes we need to hammer it into a shape that fits into a test harness. A typical example is for cutting dependencies: the function we’d like to test depends on UI, a database, or just something really intricate that our test binary can’t link […]

Default Parameters With Default Template Parameters Types

Published August 10, 2018 - 1 Comment

There is a particular case for default parameters: it’s when their type is a template type. Even though the idea is similar to the regular default parameters, there are some subtleties that are worth mentioning. To illustrate this, I will use the example of map_aggregator, the output iterator for aggregating data into a map, for […]

Should I Use Overloads or Default Parameters?

Published August 7, 2018 - 2 Comments

“Should I use overloads or default parameters”, haven’t you asked yourself that question? When designing an interface where the user can leave the value of an argument up to the API, two approaches are possible: Using a default parameters: void drawPoint(int x, int y, Color color = Color::Black); And using overloading: void drawPoint(int x, int […]

Getting Along With The Comma Operator in C++

Published July 31, 2018 - 11 Comments
comma operator C++

The comma operator is a curious operator and seldom used, but it happens to encounter it in code. And sometimes by mistake. Such encounters can give a hard time understanding the code. For this reason it is useful to know what it does, and what it doesn’t do. This article is not made to show […]

How to Convert a String to an int in C++

Published July 24, 2018 - 14 Comments

Today’s guest post is written by guest author jft. In this article, he presents us a thorough comparison between the various ways C++ offers to extract number from a string. You will see how they differ from each other in terms of features as well as in term of ease of use in code. Interested […]