Sam Gentle.com

Minimum unit of code

One thing that has been difficult about prototyping, and specifically about trying to stay on the small end of the idea triangle, is that it's really hard to write small amounts of code. I wrote about that before in terms of setup costs and tooling, but I think there is a wider problem which is just that there's not really a place for very small amounts of code.

Right now, the smallest unit of code tends to be a program. But a program includes certain expectations about size and complexity. Often a program will include a build and compilation system, dependencies, and whatever it needs to talk to the surrounding environment. That's an inherent part of the operating system metaphor; each program in the operating system is an independent unit that can take very little for granted about the other units. Usually that means there is a lot you do from scratch in each program because you have to build up from a low level.

Imagine something like this: you're a designer who has just learned about the golden rectangle and you think it's super neat. You want to have easy access to it so you can use it in your designs. The function is really simple. For example, here's the code to give you the long side of a golden rectangle given the short side in Javascript:


function golden(shortSide) { return shortSide * (1 + Math.sqrt(5)) / 2; }

Now you have that code. Where are you going to put it so you can use it? There's no place to just put a function on your computer. Probably what you would do is put some interface around it, maybe a command line tool if you're a programmer, or a little widget or webpage or something. But all of those things are much larger than a single function! Your minimum unit of code has to be large because the operating system doesn't have an interface that would allow for anything smaller. It only knows how to run programs, not functions.

What I would like to see is a hybrid programming/operating environment, where even very small units of code can be stored, inspected and run the same way that whole programs are today. If you can get the minimum unit of code small enough, I think it would change the way we use computers significantly, away from passively consuming the programs of others and towards writing small bespoke units of code for ourselves.