This is the age of code components. Web, React, Angular, Vue, and even Node components are the building blocks of pretty much everything these days.
This makes sense. Software should be built by composing smaller, isolated functionalities together. Modularity and reusability are key for composability. When designing software, we should be designing a composition of smaller functionalities. When I say small, I don’t really mean X or Y lines of code. What I do mean is small in the sense that it handles a single focus or responsibility.
On Reusability And Modularity
More and more, particularly when it comes to web components, it seems like designing isolated and reusable components is not only simpler than it used to be, it’s sometimes the only right way to design them.
So, how come achieving true reusability for code components remains such a challenge? the answer lays not in design, but rather in the question how do we create, find and use these components.
Micro Packages Are Not The Answer
Obviously, we don’t want to be copy-pasting components everywhere. Duplications are very bad, and there is no need to elaborate. The problem is, up until not the only alternative to duplicating code was publishing these components as packages, or “micro-packages”.
I don’t think small components should become packages. Packages are not fit for making them practically reusable, and they add too much complexity. Here is why:
Initial overhead: to create a new repository and package for every small component you would have to create a repository, the package boilerplate (build, testing, etc.) and somehow make this process practical for a large set of components.
Maintenance: modifying a repository and a package takes time and forces you to go through multiple steps such as cloning, linking, debugging, committing, republishing and so on. Build and install times quickly increase and dependency hell always feels near.
Discoverability: it’s hard if not impossible to organize and search multiple repositories and packages to quickly find the components you need. People often used different terms to describe the same functionality, and there is no single source of truth to search and trust.