How much abstraction is too much?

How little is too little?

When you keep working with "low level" elements on a routine basis and you constantly feel like you don';t want to be doing this. Abstract 'em away.

So when is it too much?

When you can't make bits and pieces of some code parts on a regular basis and have to debug them down to the previous layer. You feel this particular layer does not contribute anything, just an obstacle. Drop it.

Where's the sweet spot?

I like to apply the pragmatic approach. If you see a need for an abstraction and understand how it will improve your life, go for it. If you've heard there should be "officially" an extra layer of abstraction but you're not clear why, don't do it but research first. If somebody insists on abstracting something but cannot clearly explain what if will bring, tell them to go away.


So when is it too much? At what point do the empty layers and extra "might need" abstractions become overkill? How little is too little? Where's the sweet spot?

I don't think there is a definitive answer to these questions. Experience is needed to develop a feeling of what is "too much" and "too little". Maybe the usage of some metric or quality control tools can help, but it's hard to generalize. It mostly depends on each case.

Here are a few links that might inspire you in the quest of answers:

  • You ain't gonna need it
  • The use/reuse paradox
  • Project triangle: good, fast, cheap
  • All problems in computer science can be solved by another level of indirection (David Wheeler)

Development is all about finding the right balance between the various tensions that are present in any software engineering effort.


The point of abstractions is to factor out common properties from the specific ones, like in the mathematical operation:

ab + ac => a(b + c)

Now you do the same thing with two operations instead of three. This factoring made our expression simpler.

A typical example of an abstraction is the file system. For example, you want your program to be able to write to many kinds of storage devices: pen drives, SD cards, hard drives, etc...

If we didn't have a file system, we would need to implement the direct disk writing logic, the pen drive writing logic and the SD card writing logic. But all of these logics have something in common: they create files and directories, so this common things can be abstracted away, by creating an abstraction layer, and providing an interface to the hardware vendor to do the specific stuff.

The more the things share a common property. The more beneficial an abstraction can be:

ab + ac + ad + ae + af

to:

a(b + c + d + e + f)

This would reduce the 9 operations to 5.

Basically each good abstraction roughly halves the complexity of a system.

You always need at least two things sharing a common property to make an abstraction useful. Of course you tear a single thing apart so it looks like an abstraction, but it does not mean it's useful:

10 => 5 * 2

You cannot define the word "common" if you have only one entity.

So to answer your question. You have enough abstractions if they making your system as simple as possible.

(In my examples, addition connects the parts of the system, while multiplication defines an abstract-concrete relationship.)