What’s a “thunk”?

An archaic old name for an old concept

I remember when everyone started talking about using “thunks” in Redux to execute code without blocking the UI. And I remember getting tripped up on the word “thunk”. What’s a “thunk”? Why are we calling it that?

The term “thunk” goes all the way back to ALGOL 60! It’s a play on “think”, because the ALGOL compiler needed to “think” about what sort of subroutines to generate. ALGOL allows passing expressions as arguments to subroutines, not just constants. One way of allowing this is to substitute the expression for another subroutine that evaluates the expression when the original subroutine call happens. This new subroutine is the “thunk” - the result of the “thinking”.

Read more →

jq -n --argjson

A tip for using jq with more than one input

jq, a tool for manipulating JSON data, is one of the easiest most powerful ways to work with JSON text values in a terminal. I use it frequently. Mostly, I use it to extract values from HTTP responses. To combine multiple files or program outputs, some extra paramaters are useful.
Read more →

Don’t use mocks

Writing good unit tests is made much easier by dependency injection. This lets you separate your code’s behavior from that of your dependencies.

Many people use mocks to add dependencies to unit tests. I think this is usually a mistake.

Read more →

Supreme Court DoS attack

Just Buy All the Lawyers

In the latest edition of Casey Newton’s newsletter, Platformer, he makes the case for why the plaintiffs in Gonzalez vs Google botched their oral arguments. The mechanism is fascinating.
Read more →

Looking in Go’s Mirror: How and When to use reflect

This article was originally published on gopheradvent.com

reflect can be intimidating to new Go programmers because it’s very generic and you lose access to many niceties in the language. But it doesn’t have to be. Let’s build some programs that use reflect as a way to demystify the package and illustrate the power and pitfalls that come with using it.

Read more →

What is software for?

it ain't all good

In the last blog, I wrote a few things that software is for:

  • putting people on the moon
  • safely deploying airbags
  • making my bank account add up

Read more →

Code is not Prose

or even poetry!

Once a month or so, this idea comes rambling out of the programming community1:

Software is prose. It is written to communicate ideas to others, it has the interesting side effect that it can be transformed into something a computer can execute.
- Chet Hendrickson

This sounds nice on paper. It makes for a good conference talk about how to structure software, how to design programming languages, and how to collaborate. I agree with what I think is the intent: write software so that other people can understand it and change it as they need to.

Read more →

Nasty refactorings with go.mod replace

alias the pain away

At work I’ve been building a new program on top of an SDK that’s under very active development. After about 6 weeks without updating the version, the SDK had deleted some code I was using and had a ton of breaking changes. If I’d simply updated the library, my entire program would fail to build, and it also wouldn’t be clear how to get it back to a good state. Following in the spirit of Branch by Abstraction, I’d rather introduce the new code side-by-side with the old and incrementally migrate without breaking the program.

Read more →

Caroline Ellison is not a sympathetic figure

yeah, I said it.

I recently read this Washington Post Article (archive.org) titled Caroline Ellison wanted to make a difference. Now she’s facing prison. After the first read-through I was incredulous at the sympathetic presentation in the biography. It reads like a resume, like a “it all spun out of control!” story about someone who got in over her head. I tweeted:

Lol how do you get such a sympathetic bio after stealing billions of dollars @GerritD

Read more →

Unmarshaling JSON in Go: The weird parts

Some tricky bits

JSON deserialization is Go seems easy, but there are a lot of tricky parts. Come and see!
Read more →