A lot of languages use braces to structure code. But in C++, braces are much more than mortar for holding blocks of code together. In C++, braces have meaning. Or more exactly, braces have several meanings. Here are 5 simple ways you can benefit from them to make your code more expressive. #1 Filling all […]
Since C++98, the C++ standard library has provided std::less, a little component that concisely expresses that you want to use operator< to perform comparisons. std::less is a template class, conceptually equivalent to this: template<typename T> struct less { bool operator()(T const& lhs, T const& rhs) { return lhs < rhs; } }; Let’s see how std::less, as well […]
This is a guest post from Valentin Tolmer. Valentin is a Software Engineer at Google, where he tries to improve the quality of the code around him. He was bitten by a template when he was young, and now only meta-programs. You can find some of his work on Github, in particular the ProtEnc library […]
As explained in item 53 of Effective C++, you should “Pay attention to compiler warnings”. In the vast majority of cases, the compiler has a good reason to emit them, and in the vast majority of cases, they point out to an oversight in your code. But in a minority of cases, you may want […]
Long functions are hard to read, hard to maintain and hard to understand in their entirety. All in all, they contribute to making our developers lives more difficult. But there is one nice thing about long functions: bashing them down into smaller units to make the code more expressive. This is one of the most […]
Today we have a guest post from Dirk Reum. Dirk is a Senior Robotics Engineer in the Automation Deliver Organization at John Deere. He can often be found pushing for better coding practices both in his group and the rest of the organization. Dirk can be found on twitter @dreum. To see an example of […]
Today we have a guest post from Andrey Karpov. Andrey is a co-founder of the PVS-Studio project. He is a Microsoft MVP in the nomination ‘Developer Technologies’ and an author of a large number of articles dedicated to the code quality and error patterns, that C++ developers make. Gradually and imperceptibly we get the situation […]
Constant values are an everyday tool to make code more expressive, by putting names over values. For example, instead of writing 10 you can write MaxNbDisplayedLines to clarify your intentions in code, with MaxNbDisplayedLines being a constant defined as being equal to 10. Even though defining constants is such a basic tool to write clear code, their definition […]
This is Part 2 of guest author Rafael Varago‘s series on composing nullable types. In this episode, Rafael presents us absent, a generic library to compose nullable types in C++. In the first part of this series, we saw how C++20’s monadic composition will help us to compose std::optional<T> in a very expressive way. Now […]
This week we have a series of two articles on composing nullable types written by Rafael Varago. Rafael is a Software Engineer at eGym GmbH, he’s been working with C++, Scala, Go, build systems (e.g Modern CMake), embedded applications, and distributed systems. He enjoys Declarative Programming and Modern C++. Rafael loves learning new technologies and […]