Data-shaped and code-shaped problems

I once stumbled upon a page on quat's garden titled “The inner platform effect”. Said page is (at least as of me writing this) fairly empty, but it does have this very interesting quote:

I’ve been thinking before about how some problems are data-shaped but other problems are inherently code-shaped, and trying to massage code-shaped problems into data-shaped ones just ends up with a mess

He goes into more detail on another page about Minecraft's datapack format:

Data resists abstraction

You want to create recipes for sixteen colors of stained glass. What to do.

In any reasonable programming language, you loop over the colors and stamp out a recipe for each color. In datapacks, because data is not code and you don’t have loops or functions, you must create a recipe file for the red stained class, copy and paste it for the orange glass, copy and paste it for the yellow glass…

This is so ridiculous to expect of people that Mojang doesn’t even dogfood their own datapack system. They wrote internal tools that stamp out thousands of JSON files based on a code specification (“data generation”). The ideas live in code, then they’re flattened into a bunch of json files, then they’re read back by more code. The JSON files are just an intermediate format.

(It didn’t have to be like this: Factorio uses an embedded copy of Lua. If you want to create sixteen items you can just use a loop!)

The Minecraft problem, as I understand it, is that they're using a data format to describe what goes on in the game, but that data format sucks, and the tooling for it is basically nonexistent. I'm not a Minecraft modder, so go read that blog post if you want the scoop.


The idea of “data-shaped” and “code-shaped” problems is one that frequently re-appears in my mind as I work on all sorts of codebases. Think devicetree (static structure describing hardware) vs ACPI (basically a programming language), or writing out GUI markup in a dedicated language (e.g. HTML, GTK's .ui files) as opposed to in code (e.g. in JS with React, or with GTK's widget creation functions).

You'll find, though, that I tend to gravitate towards static data formats, rather than describing things in code; and the separation of data from code.

A good example of this is GTK. The UI definition can be built by a builder, and it only defines the widget tree and its properties. All of the logic - i.e., the things that require making decisions at runtime - stays in the code, and the two layers are joined together by signals/callbacks and property bindings.

You could argue that jumping between the data and code is annoying. I don't really think it is - I like that it draws a clear separation between the frontend (or the part that the user sees), and the backend (the business logic), which helps reduce the cognitive load of having to figure out from the code what the final product will look like.

It also has the benefit that different teams can work on the data vs code, with minimal coordination for the glue layer. A UI designer can load up the UI in a preview tool and mess around with it, and get back a result that the coder can quickly wire to their code.

I think datagen is fine, so long as it's not overused, or used to implement pseudo-logic in the data format. Your device hardware description data format does not need to run functions. Your driver or kernel or OS does. Likewise, your config files don't need if statements, and if they do, then you should rethink those config options.

Last updated on