Filtering Unique Items from Heterogeneous Lists at Compile Time

March 20, 2022

This article is about how to filter unique items from heterogeneous lists on the type level in Haskell. This example, without further context, might look a bit esoteric by itself, but I learned a lot writing it and wanted to share the experience.

Read more

NixOS Community Oceansprint 2021 Report

December 12, 2021

This is my trip report from the awesome NixOS community hackathon on Lanzarote. For more information please also have a look on the website:

Read more

Setting up a C++ project environment with nix

April 17, 2019

This article explains how to quickly set up a C++ project environment with complete toolchain- and dependency management with nix. nix is a powerful package manager for Linux and other Unix systems (It is indeed a more powerful alternative to conan and docker) that makes package management reliable and reproducible. After setting up the project and playing around with it, we will parametrize the project description in order to automatically build it with different compilers and dependency library versions (GCC 7 & 8, Clang 7 & 8, lib boost 1.6.6 - 1.6.9, lib poco 1.9.0 & 1.9.1).

Read more

Managing libraries with Nix

February 27, 2018

While learning Haskell and using its really smart library dependency management tools (cabal and stack), i realized that the C++ eco system has a problem: There are no handy established tools that let the developer declare which libraries (and versions) are required for a project which can then be automatically installed in a portable way. Nix however convinced me to be more versatile and powerful than Conan and handier than Docker, Vagrant, etc. (although it’s fair to say that i am mixing use cases here a little bit!) In this article, i am going to showcase this great tool a little bit.

Read more

Iterators are also part of the C++ zero cost abstractions

July 2, 2017

This article picks up an example operating system kernel code snippet that is written in C++, but looks like “C with classes”. I think it is a great idea to implement Embedded projects/kernels in C++ instead of C and it’s nice to see that the number of embedded system developers that use C++ is rising. Unfortunately, I see stagnation in terms of modern programming in embedded/kernel projects in the industry. After diving through the context i demonstrate how to implement a nice iterator as a zero cost abstraction that helps tidy up the code.

Read more

C++17 STL Cookbook

June 30, 2017

This article is about the C++17 STL Cookbook, which got published this week. After about 6 months of writing, I am happy that it is out the door and hope it helps and inspires its readers to write modern C++ code.

Read more

A reinterpret_cast Trap

January 22, 2017

Sometimes, casting is just inevitable. And then there’s even not much science behind it, at least it seems so. Once some address is provided in a variable of the right size, a typed pointer can be casted out of it, and then the object can be accessed via its members and methods as usual. In some situations it is really easy to get the casting wrong, leading to interesting bugs. This article describes an example situation and a proper fix.

Read more

Python Style printf for C++ with pprintpp

November 5, 2016

The C++ STL comes with stream style character output, which is an alternative to the classic printf like format function collection of the C library. For different reasons, some C++ programmers still stick to printf like formatting. This article demonstrates the pprintpp (open source, and available on Github) library, which tries to make printf use comfortable and safe while avoiding any runtime overhead.

Read more

Do Not Fear Recursion

September 11, 2016

There are a lot of algorithms which can be implemented using recursive or iterative style. Actually, everything can be implemented in both styles. For a lot of algorithms, the recursive version is simpler to read, write, and understand. But nevertheless, programmers know, that recursive functions burden a lot of memory consumption, because there is usually a call instruction per recursive call, which puts another call frame on the stack. Interestingly, this is not true for some special cases.

Read more

Wrapping Algorithms into Iterators

September 4, 2016

Sometimes there is the requirement to generate a range of numbers from some algorithm. Be it a simple range of increasing numbers, or only odd numbers, or only primes, or whatever. Some calculations can be optimized by memorizing some values for the calculation of the next number, just as this applies for fibonacci numbers. This article shows how to wrap such calculations into iterators in order to have performant, and nicely encapsulated algorithms.

Read more