Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should you add a dependency or write the code yourself? #2

Open
alextes opened this issue May 28, 2017 · 1 comment
Open

Should you add a dependency or write the code yourself? #2

alextes opened this issue May 28, 2017 · 1 comment

Comments

@alextes
Copy link
Owner

alextes commented May 28, 2017

Some developers feel uncomfortable taking on dependencies for simple problems. For example making a POST request, or checking if a number is equal to -0.

Should you only use the language, browser APIs, and NodeJS core modules for simple problems, or is it perhaps better to take on dependencies?

@ljharb
Copy link
Collaborator

ljharb commented May 28, 2017

NIH is a cancer.

It's always better to take on well-abstracted dependencies, because if in fact it is easy to implement it yourself using "vanilla", it'll be easy to replace it later. In the reverse scenario, if you don't take on the dependency, you may later discover you're missing important pieces of the picture - and it will likely be much harder to replace your homegrown solution with a dependency later.

In the rare case where no dependency exists of sufficient capability or quality, you have two options: write one yourself and publish it, thereby enriching human society; or write a PR and improve whatever's out there already. Anything else is at best selfish, and at worst a disastrous decision.

All that said - there are plenty of things built into JS, into node, and into the browser, that work well, are reliable, and are easily polyfilled/shimmed. It is worth evaluating a dependency much more conservatively here, with an eye for readability, maintainability, cross-engine quirks and bugs, etc.


Pro-dependency zealots (who audit their dependencies to ensure well-abstracted/well-encapsulated APIs) can result in a codebase that's got an annoyingly high number of deps, but is likely easy to refactor back to having fewer.

Anti-dependency zealots (who reinvent everything with "vanilla" primitives) almost always result in a codebase that has little to no deps, but that is exceptionally difficult to refactor later to use a dependency when needed.

sindresorhus/ama#10 (comment) is also worth reading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants