Jonathan Boccara's blog

A new post every Tuesday and Friday morning

Can you write expressive code? – Christmas break challenge

Published December 19, 2016 - 1 Comment

Before you go away on holidays and feast on Christmas and New Year’s eve parties, I want to propose you a challenge about writing expressive code to keep your skills up during the holidays period. I’m going to show you the code for a simple task performed by an application. I’m even going to explain that code to you. […]

It all comes down to respecting levels of abstraction

Published December 15, 2016 - 2 Comments

As software developers, we get to learn many good practices and strive to apply them in our code. For instance we learn the importance of good naming of variables and functions, encapsulation, class cohesion, the usage of polymorphism, concision, readability, code clarity and expressiveness, and many others. What if there was only one principle to […]

Passing strong types by reference – First attempt

Published December 12, 2016 - 2 Comments

In this post in the series about strong types, we focus on the need for passing strong types by reference. This is a fairly common use case for strong types, since passing arguments by reference is so common, but I haven’t seen this aspect of strong types treated anywhere else yet. This post is part of the following series: […]

Strong types for strong interfaces

Published December 8, 2016 - 15 Comments

Strong types are a popular topic in the C++ community. In this post I want to focus specifically on how they can be used to make interfaces clearer and more robust. This post in the second one in the series on strong types: Strongly typed constructors Strong types for strong interfaces Passing strong types by reference Strong lambdas: […]

Strongly typed constructors

Published December 5, 2016 - 6 Comments

This is the first post of a series on the topic of expressive types, that is, types that express what they represent, rather than how they are implemented. By carrying meaning, these types improve the readability and safety of the code. Here is the series about strong types: Strongly typed constructors Strong types for strong interfaces Passing […]

Partial queries with optional<T>

Published December 1, 2016 - 5 Comments

Clearer interfaces with optional<T> showed what optional<T> was, and how to make interfaces clearer by using it as a return type. If you’re not familiar with optional, I would recommend you to read it first. Here I present a example of using optional as an argument, to leverage on its “not set” semantic. The need we’ll work […]

Return value optimizations

Published November 28, 2016 - 1 Comment

In Make your functions functional, we saw that it was preferable to have functions return objects by value, for code clarity. Now to avoid incurring performance costs by doing this, the compiler can optimize away the copies related to the return by value, if you respect a few simple rules. This post describes these optimizations and shows […]

Clearer interfaces with optional<T>

Published November 24, 2016 - 0 Comments

The need for representing a value that is “empty”, “null”, or “not set” arises regularly in code but often leads to clumsy or brittle solutions. This need may appear with a function that needs to return a value but may not be able to compute it in all cases. In this case, several solutions are […]

Make your functions functional

Published November 22, 2016 - 7 Comments

Introduction : global variables Global variables are a Bad Thing. Everyone knows this, right ? But do you know exactly why ? I have asked this question around, and many of us can’t exactly explain why global variables should be avoided. It is not a question of scope. Indeed, global constants have the same scope as […]

How I came to create Fluent C++

Published November 15, 2016 - 3 Comments

Getting better by teaching I’ve quite recently come to the realization of the immense value of teaching. Not teaching as in formal education, but rather teaching as in explaining things to people, clearing the confusion around a topic, or simply sharing something I’ve learned. In a nutshell, when you teach, you get better at the topic […]