I recently found myself squinting at two images at work and wondering if one
is actually “better” than the other. The two images were
showing the same object, but they had slightly but noticeably different value
ranges. That made it hard for me to understand which of the differences were
due to display brightness and contrast settings and which were part of the
actual structure of the image. Then I remembered a simple technique that
I’ve been using on and off since my PhD days.
…
Posted 2026-05-18 , Last Updated 2026-02-26
Read More
It’s been one too many times that I’ve seen the famous skateboard, scooter, bike,
motorcycle, and car image
by Henrik Kniberg, which he says is about (agile) “product development
in general”. I’ve finally figured out what bothers me about it so much.
I’ll argue that the underlying mental model is at best not helpful
and at worst actively misleading for product development, despite the article
making a couple of excellent points and presenting great examples. Hiding
in Kniberg’s own text and examples is a better mental model: vertical slices.
…
Posted 2026-04-07
Read More
Say we have a sequence of independent Bernoulli
experiments and we want to make claims about the true probability of success,
given our observations. How many trials do we need to make claims about the true
probability with a certain confidence? Let’s derive this from first principles.
…
Posted 2025-11-18
Read More
This is a story of testability, multithreading, and the age old question of
how do we send a !Send type in Rust. I’ll explore how (not) to do this,
while rambling on about how writing obsessively testable code leads to better design.
Hot takes incoming.
…
Posted 2025-05-24 , Last Updated 2025-05-26
Read More
This article continues the series on Variable Projection and
explains how to rewrite the problem using QR decomposition, rather than the more
computationally expensive singular value decomposition (SVD).
…
Posted 2025-03-16 , Last Updated 2025-03-20
Read More
Inspired by Jack Wrenn’s post on Undroppable Types
in Rust, I set out to see if it’s possible to create types that must be used exactly
once. From my understanding, those things are called linear types, but
don’t quote me on that.
…
Posted 2024-11-27 , Last Updated 2024-11-29
Read More
While using compile-time builder generator crates, I realized that I had run into
a niche problem that required lot more flexibility with generic structs and
functions than I was getting. If you like, follow me down a rabbit hole
and explore the builder pattern from a very generic-centric perspective.
…
Posted 2024-10-11
Read More
In this article, I explore how to efficiently calculate the covariance matrix
of the best fit parameters for global fitting problems that use the
variable projection (VarPro) algorithm. It’s a very niche topic, but I do need it for
my open source library so I might as well write it down. It might be helpful
for people looking to gain a deeper understanding of the math behind VarPro.
…
Posted 2024-09-30
Read More
In this article, we’ll derive from scratch the well known formulas –and some not so well known
ones– for nonlinear least squares fitting from a Bayesian perspective.
We’ll be using only elementary linear algebra and elementary calculus. It turns
out, that this is a valuable exercise, because it allows us to clearly state our
assumptions about the problem and assign unambigous meaning to all components of
the least squares fitting process.
…
Posted 2024-07-18 , Last Updated 2024-08-21
Read More
When using Rust, it’s easy to forget about segfaults, buffer overflows, and related
memory safety bugs. Recently, I had a problem when I linked a C++ library to my Rust executable
and said library was producing segfaults (among other things). The way I decided to tackle the
problem, was to use Address Sanitizer (ASan). I’ll summarize the procedure here in case anyone
else runs into the same problem and they might find this useful.
…
Posted 2024-07-12
Read More
What do you do if you want to code using an (almost) fully featured IDE setup, but
you’re up 40,000 feet in the air, without internet? And you don’t want to pay for
business class? I’ll show you what I did and I’m definitely
interested in feedback and other solutions to this problem.
…
Posted 2024-06-10
Read More
About three years ago, I announced in my previous article
on variable projection, that I would write a follow up about VarPro with
multiple right hand sides. This is it. Global fitting with multiple
right hand sides is an application where VarPro shines because it can
bring significant computational savings. Let’s dive right in.
…
Posted 2024-01-10 , Last Updated 2024-08-28
Read More
Announcing a major update of my article on the variable projection algorithm,
which you can find on this blog by following this link.
The article now contains all the information you need to implement your own
VarPro library in a language of your choice.
…
Posted 2023-12-17
Read More
Starting out in Rust as a C++ developer, one of the features I missed most
at first were constructors. In this post, we explore the many roles that
constructors have in C++ and see how they can (or can’t) be mapped to different
parts of the Rust language. Although I’ll use C++ terminology,
this article is likely helpful for developers coming to Rust from other
languages as well.
…
Posted 2023-11-25
Read More
The moment that spawned this article was when I asked myself how hard
can it be to make sure two types have the same size at compile time? Well…
it’s complicated. In here, we’ll do a deep dive into the limits of compile
time metaprogamming in today’s (and tonight’s) Rust.
…
Posted 2023-09-01 , Last Updated 2023-09-07
Read More
A project of mine required me to dive into unsafe Rust and
when I was done with it, I had understood something that I wanted to share.
However, since I wasn’t sure if I made any subtle mistakes, I did ask the community to
review my code and oh boy did it turn out that I had missed some vital things.
Bear with me and hopefully you’ll gather something useful, too.
…
Posted 2023-07-24 , Last Updated 2023-08-07
Read More
No, this post does not contain cruelty towards animals but only to our own sanity. We will explore a
particular aspect of how Rust’s trait objects work behind the scenes and
take a deep dive down the rabbit hole. Sometimes it’s good to be reminded that
all the nice things we have as programmers are just sugar on top of ones and zeros in the imagination
of some sand that we tricked into thinking.
…
Posted 2023-03-15 , Last Updated 2023-04-23
Read More
This blog now has a feed to which you can subscribe using the
RSS logo at the top or at the bottom of the page. Or by clicking here.
Updates to this blog are not frequent, but they are mostly high-effort posts
and I am happy if they reach a lot of people, so if you like my stuff please
subscribe :)
…
Posted 2023-03-02
Read More
I used to like C++. I still do, but I used to, too. Joking aside, I am not one
to tell any C++ programmer to just use Rust. There are a ton
of valid reasons why companies or individuals decide to use C++ and I don’t
wish to deter anyone from doing so. What I am trying
to do in this article is to see how Rust stacks up against a handful of
very common (and severe) bugs that are easy to produce in C++. I tried to make
this article worthwile for both Rust and C++ programmers.
…
Posted 2022-12-21 , Last Updated 2022-12-26
Read More
The rayon library is a brilliant piece of engineering that is so simple to use
that one seldom has to descend into its depths. This is the story of how I
learned to implement rayon’s
ParallelIterator
trait for my own type. There are tons of guides on how to use rayon’s parallel
iterators and there are a few explanations on how they work under the hood. However,
I found no tutorials on how to implement a parallel iterator from the ground up.
This article aims to close that gap.
…
Posted 2022-10-30 , Last Updated 2022-11-01
Read More
The other day I wondered if there is a way to metaprogam a syntax that returns
a type based on a conditional expression akin to an if…else if…else expression.
The idea came to me when I searched for a programmatic way to choose the right
size of integer for a bitset, given a certain number of bits. And yes, I know
there’s std::bitset, but I’ll take any excuse to investigate an interesting metaprogramming problem.
…
Posted 2022-08-20 , Last Updated 2023-03-24
Read More
Recently I hit a stack overflow error in Rust and I found a helpful quick and dirty way of debugging it using a tool that a friendly
member of the community hacked. If you hit a stack overflow and are too lazy to fire up your debugger, this article is for you.
…
Posted 2022-07-25
Read More
A while ago I wrote an article about a small project that I did in the Zig Programming Language about controlling GPIO on the Raspberry Pi. Zig is a neat language and the whole project ended up being a whole lot of fun. You can read the article here. Although Zig is a very new – and, at the time of writing, immature– language I encourage everyone to take a look, because rather than aiming to replace C++ in all its power and complexity, it aims to replace C which makes it conceptually very different from a language like Rust.
…
Posted 2022-03-21
Read More
By popular demand this site now supports both a light and a dark theme. There is no explicit way to switch between light and dark mode, instead the site will adapt to the browser preferences.
…
Posted 2021-10-23
Read More
I am currently getting into embedded programming with C at work and while there are some things I learned to appreciate about the simplicity of C, two of the things I really miss are generics and stricter type safety. I wondered if C++ can offer a safer way of reading types from arrays of bytes. This, of course, gives me an excuse to work out my C++ template metaprogramming muscles, which have atrophied a little.
…
Posted 2021-10-08
Read More
In a recent attempt to write some clever code, I set out to implement mutually exclusive traits and some blanket implementations involving these. In doing so, I hit the limits of what the compiler can do for me, but after a lot of trial-and-error, researching, and flashing the bat signal to the Rust community I had something that worked. This is how to get mutually exclusive traits working in current Rust for Future Me™ and anyone else who might be interested.
…
Posted 2021-07-31
Read More
In the last months, I have been developing three crates for Rust. All of these crates are open source libraries that use different aspects of the language. The first crate is a numerics library, which emphasizes interfaces that are powerful but simple to use. The second one is a fluent coding library using mostly declarative macros and the third crate uses procedural macros to help with expressive assertions. For my next series of posts I am going to introduce these three crates and highlight a particular aspect of each one. First up is the varpro library.
…
Posted 2021-05-27
Read More
Inspired by the previous article on creating a common interface to call and pass functions of different numbers of arguments in Rust, I wanted to see if and how I could make this work in C++. I was able to get a very similar thing working in C++ at the expense of some of my sanity. Here we go.
…
Posted 2021-02-25
Read More
I am working on a little numerics project where the goal is to let the user pass base functions to a data-fitting model in a simple fashion. And while I really like what Rust’s lambdas can already do for me, I was wondering if I can pass functions with different (but compile time constant) numbers of parameters using a single interface. It turns out that I can, and the answer is a nice combination of Rust and C++ metaprogramming idioms.
…
Posted 2021-02-15
Read More
I was going to write something about how windowing could be used to mitigate the effects of spectral leakage in the DFT. However, I went down a rabbit hole trying to truly understand where spectral leakage comes from and how it relates to the periodicity of the DFT. What I ended up writing, is a post that is more about understanding the DFT and less about windowing, although it plays an important role in this post.
…
Posted 2021-01-17
Read More
I have extensively worked with the Fourier transform and the DFT but never really taken the time to understand how these two things are truly connected and how that connection explains some of the properties of the DFT. In this article I explore this connection with the aim of answering one question: what does the DFT actually compute?
…
Posted 2020-12-30
Read More
In the previous post on concurrency we have explored the different paradigms for protecting shared data with mutexes in Rust versus C++. Here we will look at emulating a Rust Arc<Mutex<T>> type to protect concurrent access to a shared resource of type T in C++.
…
Posted 2020-12-01
Read More
I have been using Rust in production for a couple of months now and there is lots about it that I like. One neat thing is that Rust’s compile time guarantees make memory and thread safety much harder to mess up from the get go. This allows Rust programmers to confidently use some paradigms that are harder to use correctly in C++. One such example is protecting shared data with mutexes, which works very differently in Rust than in C++. This post is about exploring those fundamental differences.
…
Posted 2020-12-01
Read More
I recently got it into my head to write a compile time version of the FizzBuzz Coding Kata. Coding Katas are a great way of improving our programing skills, so why not use them to improve our metaprogramming skills as well? Here’s what I came up with.
…
Posted 2020-09-15
Read More
I came across the problem of printing a tuple of different types to cout and thought I would jot down my solution. This isn’t an original solution of mine, but I wanted to remember the ideas behind it, so I am writing it down for Future Me™ and anyone else who’s interested.
…
Posted 2020-08-18
Read More
In this part we will complete the implementation of the if expression to replace the ternary operator. Furthermore, we will look into limitations and extensions of the implementation.
…
Posted 2020-07-24
Read More
Right now I am getting into Rust, which lets me see the paradigms of C++ in a new light. This is a small thing, but for example: C++ has if statements and Rust has if expressions which can return a value. This inspired me to implement an expressive syntax for mimicking Rust’s if expressions in C++. To keep things simple, I only targeted the use case of replacing nested ternary operators.
…
Posted 2020-07-06
Read More
This is the last part of my series on a pipe syntax for operations on std::optional types. We will look at switching between function overloads at compile time using std::enable_if to implement the last puzzle piece we were missing before. I will also show some limitations of my implementation and describe how my pipe operator fits into the overarching idea of functional programming.
…
Posted 2020-06-07
Read More
The Variable Projection method is a lesser known algorithm in the domain of
nonlinear least squares fitting. It is interesting because it makes
clever use of linear algebra to potentially speed up fitting certain classes
of functions to data. I’ll introduce the method
such a way that it will enable you to implement your own varpro library in your
favorite programming language. Only a basic understanding of linear algebra and calculus is required.
…
Posted 2020-05-24 , Last Updated 2023-12-22
Read More
I’ve started implementing a pipe syntax to apply callables to optional values in a more expressive fashion here. However, I still needed a way to provide a useful return type if the callable itself returns an optional. I will implement this functionality using Template Metaprogramming.
…
Posted 2020-05-18
Read More
I set out to implement my high concept null conditional operator for std::optional and ended up with something significantly more low concept. Still, I did learn a lot about template metaprogramming and ran into some interesting pitfalls. Let’s see what I did in this multi-part series.
…
Posted 2020-05-17
Read More
Assume we want to estimate the mean for Poisson count data: is it better to keep all the data, or is the sum and the size of the dataset enough? Let me do the calculations here. I’ll also give the posterior distribution for three different choices of prior.
…
Posted 2020-05-16
Read More
These are the results of my foray into Bayesian data analysis applied to a children’s game. This post ties the previous posts concerning simple games, probability theory, and functional programming together. After recapping the rules of the particular game, I will present the winningest strategy, which will surprise nobody. But I will finish with a plot twist.
…
Posted 2020-05-15
Read More
These are my calculations to understand the credible intervals for a Binomial Distribution under the Normal approximation from a Bayesian perspective.
…
Posted 2020-04-20
Read More
In the last article, we looked at creating immutable objects in C++ using immutable member variables. Here we will look at immutability through interfaces that let us take advantage of move semantics.
…
Posted 2020-03-31
Read More
In an attempt to increase my functional programming skills in C++, I went full functional when writing a simulation for a children’s game. Trying to implement a game state using the paradigms of functional programming presents some interesting challenges. In this post, I will explore the concept of immutability and how we can implement it in C++ for all kinds of stateful objects.
…
Posted 2020-03-10
Read More
This post is a little sidenote to the last post on the Bayesian analysis of a game for children. Here we will calculate the expression \(P(X>Y \vert I)\) given information about two variables \(X\), \(Y\).
…
Posted 2020-02-19
Read More
This blog now has a comment functionality. I can switch on comments for individual posts and everyone with a GitHub account is able to comment.
…
Posted 2020-02-16
Read More
While playing a boardgame for three-year-olds with my daughter, my mind started to wander. Boardgames for young children give the player very little agency to influence the game, if any. Yet I wondered what the best playing strategy for this particular game was. The game is simple enough that I can start writing a simulation, but now I am faced with the problem of how to interpret the data. How confident can I be that one strategy really is better than the other? Deriving these answers from scratch is the topic of this series.
…
Posted 2020-02-08
Read More
In C++, std::optional<T> is a great way to represent a type that could hold a value of type T or nothing. However, it is somewhat clumsy to work with optional types when you want to chain operations on them because you have to account for the nullopt case.
…
Posted 2020-01-23
Read More
Older posts are available in the archive.