Modularity vs. Abstraction. Which is More Important?

Coupling? Bad.

Coupling is the enemy of modularity. Coupling creates the need to understand the inner workings (implementation details) of multiple functions/objects/entities in order to understand what the code is doing.

Abstractions? Good.

Abstractions are a natural concept in this world. I do not need to understand how a car works in order to drive mine. In programming, being able to use functions and components without understanding their inner workings is a sign of well-designed abstraction. A clear and tight interface that is easy to work with is a sign of good code.

Good modularity with bad abstractions? Could be better.

It's not fun to read, but at least you know where everything is. This tends to create large components and classes, but I see it as the lesser of two possible evils.

Bad modularity with good abstractions? The worst spaghetti possible.

These types of codebases are the hardest to work with. Hiding implementation details is worthless if you're forced into a wild goose chase across the entire codebase to find out what the code is trying to even do, while it is being hidden in layers of abstractions.

The worst part is that this type of code doesn't fit into any of the traditional "code smell" categories. It's easy to have it slip by in code review. I have even seen engineers call many small functions an anti-pattern. This is simply not true. In order to have abstraction shine, you need to tighten the scope of what a programmer needs to understand in order to develop in a codebase.

Good modularity with good abstractions? Yes please.

A match made in heaven. It's no coincidence that this is extremely hard to achieve. From my limited experience, I think I do a decent job. But I'm fully aware that a master in this craft would look at my code and pick it apart into oblivion. It's still a learning process and I don't see myself converging to perfection in this regard (for the foreseeable future). It's a work in progress.

TL;DR; In my humble opinion, I believe that modularity is more important.

From my experience in the handful of codebases I've worked with, I've noticed that modular code is far easier to reason about. Amazing abstractions with 5-layer deep interlocked taxonomies has, hands down, been the worst experience I've had as a programmer. For any new programmers, I highly recommend you understand modularity like the back of your hand before you move on to implement other design patterns.

Comments

Popular posts from this blog

Contrasting var and ES6s new declarations: let and const

Unit testable components pt.3: Testing components