RSSAmplifier

Blog

Belay the C++

A blog talking about (usually bad) practices in C++

belaycpp.comRSS feed ↗10 posts

Latest posts

a = b = c, a strange consequence of operator associativity

Author: Chloé LourseyreEditor: Peter Fordham Case study If you code in C++ regularly, you probably have encountered the following syntax: In terms of semantics, this code is equivalent to the following: This is today s subject: assignment is an expression. How does it work? What is the value of such expression? If we run the following code, we ll Continue reading a = b = c, a strange consequence…

How to quantify technical debt inflation

Author: Chloé LourseyreEditor: Peter Fordham If you work for a software company, you necessarily end up in a situation where you have a technical debt to repay, but don t have the approval of your management to do so now. We ll deal with it later , they say. But, as a good developer, you know two things: technical debt Continue reading How to quantify technical debt inflation

Who owns the memory?

Author: Chloé LourseyreEditor: Peter Fordham Have you ever heard of ownership of memory, in C++, when speaking about pointers? When you use raw pointers, you have to delete them (or else, you ll leak memory). But if the said pointer is passed down functions and complex features, or returned by a factory, you have to know whose job Continue reading Who owns the memory?

3 interesting behaviors of C++ casts

Author: Chloé LourseyreEditor: Peter Fordham This article is a little compilation1 of strange behaviors in C++, that would not make a long enough article on their own. Static casting an object into their own type can call the copy constructor When you use static_cast, by defaut (i.e. without optimizations activated) it calls the conversion constructor of the Continue reading 3 interesting…

Constant references are not always your friends

Author: Chloé LourseyreEditor: Peter Fordham Early on, when we teach modern C++, we teach that every non-small1 data should be passed, by default, as constant reference: This avoids the copy of these parameters in situations where they don t need to be copied. Other situations call for other needs, but today we will focus on constant references. I Continue reading Constant references are not…

I don’t know which container to use (and at this point I’m too afraid to ask)

Author: Chloé LourseyreEditor: Peter Fordham As far as containers go in C++, since std::vector is well suited for most cases (with the occasional std::map when you need key-value association1), it s become easy to forget that there are other types of containers. Each container has its strength and weaknesses, so if you are one to forget what its Continue reading I don t know which container to use…

Retrospective: The simplest error handler

Author: Chloé LourseyreEditor: Peter Fordham This week, we ll talk about last week s article and try to be critical about it. There are a few things to say and it occurred to me (thanks to some feedback I got through social media) that it can be improved a lot. If you don t know about SimplestErrorHandler, go read the Continue reading Retrospective: The simplest error handler

One of the simplest error handlers ever written

Author: Chloé LourseyreEditor: Peter Fordham This week, I ll present you a small device I wrote to handle basic errors, the most compact and generic I could think of. It is certainly not perfect (mainly because perfection is subjective) but it is very light-weight and easy to use. If you want to skip the article and go directly Continue reading One of the simplest error handlers ever written

The three types of development

Author: Chloé LourseyreEditor: Peter Fordham This week we ll discuss a serious topic affecting the developer community. This touches several languages, but the C++ community is one of the most affected by it1. There are several ways to write C++. I mean way as a collection of constraints and circumstances that will affect what you can do, what Continue reading The three types of development

Prettier switch-cases

Author: Chloé LourseyreEditor: Peter Fordham I learned this syntax during a talk at the CppCon 2021 given by Herb Sutter, Extending and Simplifying C++: Thoughts on Pattern Matching using `is` and `as` Herb Sutter YouTube. You also find this talk on Sutter s blog, Sutter’s Mill – Herb Sutter on software development. Context Say you have Continue reading Prettier switch-cases