Jonathan Boccara's blog

How to Choose Between Struct or Class

Published March 2, 2018 - 0 Comments
struct class C++

“Should I use a struct, or a class?” Such is the question we sometimes ask ourselves when creating a new type. What’s the difference between struct and class in C++? How to to choose one or the other? This is the question we tackle in this week’s video: Transcript of the video: What’s the difference between a […]

Replacing an Else-if Sequence With a Ternary Operator

Published February 27, 2018 - 4 Comments
Ternary operator C++

One of the comments left on the Reddit thread of How to make if statements more understandable by /u/loup-vaillant, showed a suggestion to represent an else-if logic a different way, by using the ternary operator (?:) in a certain way. I find that suggestion interesting and I’d like to share it with you today. And while you’re […]

Introduction to Boost Karma

Published February 23, 2018 - 1 Comment

Following up in the series about learning what’s in Boost, let’s get in Boost Karma, that generates strings in a very, very elaborate manner. Too elaborate? Perhaps. But like most of the Boost libraries, even if you don’t end up using them in your production code, it’s still beneficial to know about them. They push […]

On Using Guards in C++

Published February 20, 2018 - 11 Comments
guards C++

Early return statements are a controversial topic across many programming languages. Some people find that they improve readability because they avoid carrying a result variable down the end of a function. And some other people find they constitute a danger because they introduce complexity: with them, a function suddenly has several exit doors. Today I […]

The Right Question for the Right Name

Published February 16, 2018 - 0 Comments
naming

“What’s the right name for this variable/function/class/module?” As programmers, this something we ask ourselves multiple times a day, and that is also a question that comes up often during code reviews. In this video, I’ll share with the question that I use to determine a name for something in code. And often, the answer to […]

To RAII or Not to RAII?

Published February 13, 2018 - 18 Comments
raii

RAII is a central concept in C++, that consists in relying on the compiler to call destructors automatically in certain cases. Putting appropriate code in such destructors then relieves us from calling that code – the compiler does it for us. RAII is an idiomatic technique of C++, but can we use RAII for everything? […]

Introduction to the C++ Ranges Library

Published February 9, 2018 - 2 Comments
C++ ranges

Announcement: This Sunday I’ll be hosting my first AMA, standing for Ask Me Anything, and I’d love for you to join in! An AMA is an online event where you can ask any question to the host. And the AMA I’ll be hosting is about writing clear code (in particular in C++)! So I will take […]

Understanding lvalues, rvalues and their references

Published February 6, 2018 - 7 Comments
lvalue rvalue references C++

Even though rvalue references have been around since C++11, I’m regularly asked questions about how they work and how to use them. For this reason I’m going to explain my understanding of them here. I think this is relevant to the topic of Fluent C++, expressive code in C++, because not understanding them adds a […]