Hacker News new | ask | show | jobs
by h8liu 3637 days ago
No dependency is often not the right dependency. For example, http depends on tcp, because an http stack cannot work or be reasonably tested without a working tcp stack. Yes, the tcp stack can be provided as an injection. Yes, the tcp stack can be defined as an interface and faked or mocked with a minimal implementation that barely supports the required execution, but still, without providing the depended tcp module, the http module does not work "independently". Sure that the http stack semantically only depends on the tcp "interface" to "compile" (if that was a thing in javascript), but as an http module that ideally should just work out of the box, it should always be shipped with a default tcp "implementation" that just works fine, rather than having the user of the module to "register" a tcp module.

Using centralized message passing/routing/registering is just being lazy on handling dependency, it is like abandoning structure programming and starts using "goto" for every branch, which makes the logic flow eventually untraceable. For a system of N modules, it ideally should have around O(N) dependency edges, but a centralized hub is essentially modeling a possibly O(N^2). It only makes sense to introduce a hub when everyone potentially wants to talk to everyone.

And worst of all, every module using the framework now depends on the "hub" now. While the actual logic-related dependencies are all converted to "dynamically" instantiated ones, this "static" dependency on the hub becomes extremely hard to remove in the long term. It's like a cancer. It is not a good "pattern".