Jonathan Boccara's blog

A Case Where Using Auto Leads to Undefined Behaviour

Published October 30, 2018 - 12 Comments

C++11’s feature auto has changed the looks of C++ code. In a lot of cases, auto alleviates code from burdening information, and using it does make code simpler. So much so that using auto becomes a second nature to make code more expressive. Should we use auto always? According to Herb Sutter guideline for C++11, yes, almost […]

Word Counting in C++: Computing the Span of a Word

Published October 23, 2018 - 6 Comments
word count span

Here is a new episode in the series of word counting! Today we will focus on computing the span words in code. As a reminder, word counting consists in counting the occurrences of every term in a piece of code (for example, in a function), and sorting the results by most frequent words. This can reveal […]

Word Counting in C++: Parametrizing the Type of Case

Published October 19, 2018 - 9 Comments

In our first step implementing a word counter in C++, we wrote code that could extract the words inside of a piece of code. In the second step, we changed that code so that it extracted individual words inside of camelCaseSymbols (and also of PascalCaseSymbols), losing the previous feature of counting entire words. Today, we […]

Word Counting in C++: Implementing a Simple Word Counter

Published October 12, 2018 - 6 Comments

Word counts can reveal information about your code, or make an unknown piece of code more expressive to your eyes. There are online tools to count words in generic text, but most of those I’ve come across are designed around counting words in text and SEO (Search Engine Optimization). Since analysing source code is not the […]

Why Optional References Didn’t Make It In C++17

Published October 5, 2018 - 5 Comments

An object of type optional<T> can take every value that T can take, plus one. This extra value represents an object that is “null” (or “empty” or “not set”, formulate it as you will). And we’ve already seen how optionals can make your interfaces clearer. The aspect I’d like to dig in deeper today is the particular […]

Pointers, References and Optional References in C++

Published October 2, 2018 - 3 Comments
pointer reference optional handle

In C++, one can manipulate objects directly or via something else, which is commonly called a handle. At the beginning of C++, handles could be pointers, references and iterators. Modern C++ brought in reference wrappers, and boost introduced optional references. The fact that a given piece of code chooses to use one particular handle expresses something. For this […]