
Ask HN: Why do JavaScript developers favour many, tiny dependencies? - confusedjs
The more I delve in to the world of Javascript the more I come across projects such as:<p>* is-root: https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;is-root<p>* is-even https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;is-even<p>Often these are whole npm modules that comprise of a single line of code.<p>I&#x27;ve never seen anything quite like it when working with Java and Python.<p>Can anyone explain why? It seems to me adding a dependency I have to suck across the network, that may introduce breaking changes (or just disappear) is something that shouldn&#x27;t be taken lightly. Doing it for a single line of code (that realistically won&#x27;t need to change anyway) is borderline insane.<p>Am I being too paranoid or am I missing something?
======
davismwfl
You aren't being paranoid IMO, but there are reasons it is done to some level.

Personally, as for depending on 3rd party npm modules that only implement a
few lines of Javascript, I generally avoid doing it as it feels wrong. I also
wouldn't say Javascript developers favor tiny dependencies, they are just
trying to generally avoid rewriting the same line of code across multiple
places since that can obviously create a lot of headaches. While there are
ways to handle includes, modules etc, across projects it can get messy fast
and cause lots of stability issues, but using small versioned packages
generally resolves those issues, at least in my personal experience.

My own basic thoughts:

1\. if you only need that code in one project, just create a small module and
include it, done.

2\. if you want to share that code amongst multiple projects utilize npm
private packages, or create a local npm repository/cache.

I generally opt to use npm private packages as it allows for easy reuse
internally across multiple projects without having to copy or reimplement
code. Plus you can take advantage of versioning them which makes life a lot
more flexible and robust.

Also, don't forget there are license terms that can affect which packages you
use too, so that has to come into play as well when you are selecting them.

------
lollipop25
Seriously? isEven? That can be done using `!(n % 2)`.

You're generalizing, and yes, you're being too paranoid. Not all of them
actually agree on (really very small) modules.
[https://medium.com/@Rich_Harris/small-modules-it-s-not-
quite...](https://medium.com/@Rich_Harris/small-modules-it-s-not-quite-that-
simple-3ca532d65de4)

It all boils down to balance and common-sense.

~~~
confusedjs
Thanks, that's some interesting discussion

------
davelnewton
Small and focused is good. Keeps from having to import a huge library (e.g.,
math.js) for simple functions when you don't need what the rest of the library
offers. Small surface.

Would _I_ use is-even? No, I'd keep it in a local utility that bundles up
other things my specific app needs, or package groups of small util libs into
an app-specific uber-module.

