Great and informative piece as always!

It reminds me of this from the Zen of Python:

Simple is better than complex.
Complex is better than complicated.

It is not until recently — when I got to work with some very complicated code — that I finally experience the differences between complex and complicated.

This is just my interpretation, and may not be totally correct.

complex: less straightforward

In my understanding, a complex function still does one thing, but does it in a less straightforward way, in order to gain some benefit. (Most commonly it is for performance gain.)

For example, the heap sort algorithm is more complex than bubble sort.

A dynamic programming solution for the longest common substring problem is more complex than the naïve version.

And you can see, I am using the naïve version in my project.

That’s because simpler code is easier to understand and debug, and it works fast enough for my use case (and I can’t find any longest common substring module on npm that works on a plain String).

I’d prefer simple code over complex code.

complicated: involves in too many affairs

I once wrote a musical score file parsing routine that goes through all the headers and events at once, all while keeping track the timing information, and generates an image from it.

The code does it in a very straightforward way. No fancy abstractions, just pure and straight code. That PHP script doesn’t even contain the word ‘function.’ Of course, the script also handles file uploads.

But it is hard to test — you can only test the final results, and it is not reusable — you can’t just reuse it in another use case.

In my new version (written in JavaScript for a rhythm game I’m developing), each part of the process becomes its own module.

And it happens that…

While the code is more complex, it is less complicated, and it is so easy to work with.

I’d prefer complex code rather than complicated code.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store