Why You Can't Divide by Zero

Well, why not? The usual answers boil down to either an appeal to arithmetic intuition (e.g. treating division as repeated subtraction, you can never subtract zero to get anywhere) or definition (you can't divide by zero because zero is defined not to have a multiplicative inverse, i.e. “because I said so”). But the former is mathematically naïve and the latter is unsatisfyingly circular. So let's dig in to why we want to define zero out of division.

More…

Light theme!

I added a light theme to the site.

More…

Covariance in a Result<T, E> Type in Kotlin

Last time, I set out to build a Result<T, E> type in Kotlin, and discovered some awkwardness around parameterizing the types of the variants. This issue, I realize I totally forgot about covariance, which significantly mitigates the awkwardness.

More…

A Result<T, E> Type in Kotlin

edit: I made a mistake in this article! See Covariance in a Result<T, E> type in Kotlin for corrections.

Kotlin provides a mechanism for sum types in the form of sealed classes. It works by closing the class for extension outside the immediate context, allowing the compiler to know every possible subtype and perform the exhaustive checking expected of the variants of a sum type. However, some typical sum type use cases are a touch awkward with this approach. Let's explore by trying to write a Result<T, E> type in Kotlin using a sealed class.

More…

Fixing freetype in Debian Buster

edit: Don't do this! Do this instead. Only read this article if you're looking for context.

Starting in Buster, Debian enabled the subpixel hinting functionality in Freetype (commonly known as the “Infinality” patches, though the enabled functionality is a small, more performant subset of the patches actually submitted by Infinality). To no one's greater surprise than my own, this badly broke my font rendering. Here's how I fixed it.

More…