Reading List

The most recent articles from a list of feeds I subscribe to.

if got, want: A Simple Way to Write Better Go Tests

There’s an excellent Go testing pattern that too few people know. I can teach it to you in 30 seconds.

Instead of writing Go tests like this:

// The common, unrefined way.
username := GetUser()
if username != "dummyUser" {
 t.Errorf("unexpected username: got %s, want: %s", username, "dummyUser")
}

Write your tests like this, beginning each assertion with if got, want :=:

// The underused, elegant way.
if got, want := GetUser(), "dummyUser"; got != want {
 t.Errorf("username=%s, want=%s", got, want)
}

The if got, want :=: pattern works even better in table-driven tests. Here’s an example from my library for parsing social media handles:

They squandered the holy grail

Why Apple Intelligence failed even though everything it's built upon is nearly perfect

trimMiddle() – the missing String trim method

One of the cool features of MacOS’ Finder app is that it does not trim file names that don’t fit the space at the end, but in the middle of the file name. This does make a lot more sense, as it also shows what format the file is. Neither JavaScript nor CSS have a […]

Go's bytes.Buffer vs. strings.Builder

Taking five minutes to write a benchmark so I know which of these I should be reaching for first.

Postgres UUIDv7 + per-backend monotonicity

How Postgres’ v7 UUIDs are made monotonic, and why that’s a great feature.