follow me on Twitter

Let's Have a War

@fernandezpablo's opinions on software development

The Simplest Thing that Works

Introduction

Most likely, you’ve heard that phrase. The full version is:

What’s the simplest thing that could possibly work?

It was coined by Ward Cunningham, one of the smartest hackers out there.

I knew the term for a long time, but it wasn’t until a few months that I actually found myself in a situation that made me actually “get it”. It was kind of an “aha moment” that I’d like to share here.

Simple, but not working

I maintain an opensource library, called Scribe, that lets you make OAuth calls without all the boilerplate. A while ago, a ticket was created to support a particular feature.

Basically, the library makes an http request, obtains a response and parses the contents. The contents are pretty much standard stuff (though some providers are too smart-ass to give a fuck about the spec).

What you get back is a string that looks like this:

oauth_token=random_string_here&oauth_token_secret=random_string_here

After some parsing using simple regular expressions (doing regexes in java is as fun as getting shot at, BTW), the lib creates this simple object, called Token, that lets you easily access the token and secret.

But again, some smart providers send you extra info there, and the string becomes:

oauth_token=random_string_here&oauth_token_secret=random_string_here&random_string_here=random_string_here

With the original Token class we don’t handle this scenario. So, for this case, scribe no longer “works”.

Working, but not simple

The guy that pointed this to me also contributed a nice patch with his solution. There are some problems with his patch, though:

What this solution does is basically return a Map<String,String> with the additional stuff that comes in the response as key-value pairs.

Is this a bad solution? not at all, the code works and the user gets more or less what he/she wants. But the library now has to inspect the string, parse it, create a map and change the public APIs to return it. It’s kind of an overkill IMHO.

Simple and Working

Here’s where “The simplest thing that works” came to my mind. I now have a different interpretation of this concept that I’d like to draw to you guys here:

simple

The idea is that the graph represents increasing complexity. Near the “simple” end, things are straightforward, easy to maintain and to use, on the “complex” end you get maintenance nightmares, your users don’t like your lib and send you hate mail or bitch about it on Twitter.

I’ve marked 3 points on the graph:

I believe now that finding that ‘B spot’ is what Cunningham meant by saying those words.

This is the solution that finally got into the lib. I believe it’s pretty close to B, because:

That’s it. Next time you have a problem in your hands, just sit back and think “What is the simplest thing that could possibly work?”. Who knows? Perhaps you’ll find a simple and future-proof solution. Just like me.