Jonathan Boccara's blog

How to Modify a Key in a C++ Map or Set

Published May 1, 2020 - 0 Comments

Contrary to sequence containers like std::vector, you can’t just assign a new value to a key of a std::map in C++, like this: auto myMap = std::map<std::string, int>{ {“one”, 1}, {“two”, 2}, {“three”, 3} }; myMap.find(“two”)->first = “dos”; Doing so makes the compiler output a copious amount of errors: error: no match for ‘operator=’ (operand types […]

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: […]

How to Extract Words among Spaces in a C++ String

Published April 17, 2020 - 0 Comments

We’ve already seen how to split a string into words with a delimiter, but there is another use case that is pretty close, and that doesn’t have the same implementation: extracting words that are among spaces in a string. For example, from the following string: “word1 word2 word3 ” We’d like to extract 3 sub-strings: […]

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 by Using C++ Ranges

Published April 3, 2020 - 0 Comments

In the last post we implemented a line filter by using standard C++14 features (with a little help of Boost), with the following interface: auto const filteredText = join(‘\n’, filter(contains(words), split(‘\n’, text))); We had to implement join, filter and split, which had the following interfaces: std::string join(char delimiter, std::vector<std::string> const& inputs); template<typename T, typename Predicate> std::vector<std::string> […]

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 […]

See you on Friday

Published March 24, 2020 - 0 Comments

Last week was the beginning of Europe locking down due to coronavirus, and a good chunk of the rest of the world is following suit this week. In those troubled times of pandemics a lot of us are staying at home and schools are closed. This can mean (at least it does for me) that […]

How Can Developers Help Fight Coronavirus?

Published March 16, 2020 - 0 Comments

Coronavirus is now transforming our lives one a day-to-day basis. As I write these lines, it is killing hundreds, infecting thousands, and scaring billions. Countries are locking down, the stock market is in free fall and all events are getting cancelled. On my end, I’m currently fighting the spread of the virus by: washing my hands […]

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), […]

3 Types of Toxic Software Projects

Published March 10, 2020 - 0 Comments

In software houses there are typically more projects opportunities to do than resources to realize them all. In my company at least, there are plenty of things we could do to make our software evolve, but only so many we have the time to invest in to and do properly. This means that being able […]

1 8 9 10 11 12 45