There is a ‘great’ quote in Software development about indirection that goes like this:

Any problem can be solved by adding another layer of indirection. David Wheeler

The follow up to this, of course, is to end it with the following:

…except for the problem of too many layers of indirection. Kevlin Henney

I am here to provide a proof of sorts, that disproves the latter and re-enforces the former.

Hypotheses:

Any problem can be solved by adding another layer of indirection, especially the problem of too many layers of indirection. Me

Let’s take a system. There is a part of the code in this system that has N layers of redirection. We define N as being too Many layers. We also make the observation that N is greater than 5. I feel confident to say too many layers is greater than 5.

We locate a seam between layers 1 and 2, and another between N-1 and N. Between these seams, we add another layer of indirection. Let’s call these LX and LY.

Now, we will remove the M layers between LX and LY into a single new Layer, called LZ. What do we have left?

L1->LX->LZ->LY->LN

We have 5 layers of indirection now. That is less than N, by the assumption that N was greater than 5 right?

To me, this feels like the proof for my hypotheses.

Questions

What if your definition of “too many layers” is actually less than or equal to 5? Well maybe that is a special case, and you should add your layers before 1 and after N? That would get you down to three layers instead?

LX->LZ->LY

I’ll leave it to you to deal with the case where N is not greater than 3 if you’re interested.

Another argument I’ve heard (yes, I actually do have discussions on these kinds of things!) was that technically the adding of the layer didn’t solve the problem but it was actually the removing of layers that made it possible. I like to think that in reality, the latter cannot really be achieved without the former, so the additional layer or indirection is the crucial step one to the whole 2-step process.

Thanks for taking some time to read this. I realise it’s probably not something anyone really needs to think about, but I had, so I thought I would share.