On dependencies

I was drafting a post about dependencies when the left-pad / NPM crisis in the node.js world came about, which prompted me to publish it now.

We constantly hear: “Do not reinvent the wheel”. Somebody already made what you are trying to achieve and there's a great chance to find it on Github. Moreover adding a foreign piece of code is actually super easy these days and we tend not to give it too much thought. Is it too easy?

BAM, here you go: you project doesn’t build because some of the dependencies are not maintained and or compatible with the new SDK.

Before adding a new dependency to your code, have a serious thought about it.

  1. Do you need it? Isn’t something that you could write within a couple of hours?
  2. What would happen if I remove this dependency?
  3. Is it properly maintained? Is it what I think it is?
Do you need it? Isn’t something that you could write within a couple of hours?

Yes if you look at left-pad it’s a nice piece of code, but really? is it not what we learn to do the first week of programming classes?

At University, our teachers made us implement the basic string functions in C. The deal was "to use a standard function you need to program it first". So we had to code strlen, strcpy, etc. Of course the stdlib implementation of strlen is faster than what we would write. But now then we knew that it's not just "magic".

What would happen if I removed the dependency?

Kaboom or Meh? Ok this is not a fair question, let's say that your rely on an external depency for the database access. Of course it's going to have an impact on your project if you remove it.

Well you can prepare for these things: encapsulation! Yes it's more work but it might save your butt in the future. Moreover if there is a better implementation later on, then it's easy to change.

I tend to think of the future in these case: How can I make it easier to change later on.

Is it properly maintained? Is it what I think it is?

Because it’s on Github doesn’t mean that it's better that what you would code.

Honestly, trust yourself. Challenge yourself a little bit. This is how we learn. Having a black box inside your source code is not a good thing.

It's really nice that we help each other by opening our code for others fellow coders to use. It’s like giving a bit of yourself to others. Sharing our implementation is a great thing! The key is when you integrate somebody else’s code, have the decency to have a look at it. Understand how the problem is solved, you might learn something.

Share your thoughts!

If you enjoyed this post, please recommend it (by clicking the ❤ button), it means a lot!