If I had more time, I would have written a shorter function

I’ve been writing a bit of code again lately.

And given the amount of time I’ve spent on it, it feels like I should have written a lot of code. I mean, I’ve been staring at this screen for days on end, alternating between trying to understand the problem for about 4 hours, then trying to solve the problem for another 4 hours, before realizing that I didn’t really understand the problem in the first place. And the cycle continues.

But yesterday, I finally solved the problem… and I’ve got nothing to show for it but a measly 200 lines of code. There’s no user interface or anything!

Still, that 200 lines has taken weeks. And during that time, when somebody has asked me “what are you up to?”, my response has been “coding”. To which their inevitable reply has been “Oh! So what are you building?”

Well, truth be told, I didn’t quite know what I was building at first. And now that I’ve built it… I still find it hard to explain.

If you asked me to be specific though, I’d tell you that I’ve built a way to reliably take all the information that an app knows about the environment it’s running in – including the URL that the browser is displaying, any cryptographic signature authenticating the app’s user, the matter of whether the app’s code has fully downloaded yet, and it’s model of any relevant data stored on the company’s servers – I’ve built a way to take all of that information and turn it into a “recipe” for rendering the screen that you’ll be looking at.

Of course, every app on the internet already does something like this.

In fact, many apps go one step further, and prepare recipes for scenarios that they predict may happen in the near future. I’ve built a way to do that too, but again, it’s old news.

So the question is, how did I manage to spend multiple weekends coding something that already exists?

Actually, I think the answer is that I didn’t spend the last few weekends coding. Or at least, I didn’t spend them building. Instead, I spent them searching for a way to take a problem that’s usually solved with thousands of lines of hard-to-maintain code, and then turning it into a problem that’s described by a single mathematically-precise function.

And now that I’ve got the world’s greatest function that nobody ever asked for, I’ll get back to trying to build something useful – content in the knowledge that whatever I build, it’ll now load that few milliseconds faster!