Should you keep your code dependency-free?
Avi Aryan
Posted on November 25, 2019
I posted this tweet on Twitter about a trending JS library 🤷🏻♂️ called Immer. Immer is a small library that helps to work with immutable data in JavaScript.
Its main purpose is helping create immutable objects which are a big pain point in the language. That’s because objects are copied and compared by reference. Hence it’s easy to do something wrong when working with them. Take a look below.
obj1 = {a: 2}
// { a:2 }
obj2 = obj1
// { a:2 }
obj2.a = 3
// 3
obj1 === obj2
// true (but why, didn't I modify obj2?)
By the way, here is my tweet. I was particularly excited about Immer because it helps with deep state updates in React. No more messing around with map
, filter
and the whole functional programming squad.
Immediately someone tweeted back about the problems of using yet another library and how it is similar to the jQuery hell. In jQuery, we have a plugin for every feature you want to add. Think parallax, modal, spinners, and whatnot. If the developer is not careful, the jQuery app soon becomes tangled because of the many non-standardised dependencies. This makes it hard to maintain.
I partly agree.
Reducing dependencies which are like out-of-your-control pieces in an application is certainly important. They also bloat the app and increase the maintenance burden. If you are not careful while using them, they can slow it down as well.
Imagine using a website or an app that takes many seconds to load or takes a lot of time to download. It’s a pain. It drives a fraction of users away and for those that stay, it wastes their time. This should be avoided when possible.
But not using a helpful dependency can also mean we are creating the solution ourselves. This can result in more time to market and more chances of bugs. Libraries and frameworks like Immer, Bootstrap, React are extensively tested to remove bugs. Creating your own solution means you will have bugs that will crawl out to the end-users.
Again something we don’t want.
As a developer, our most important job is to create things that solve problems. It’s very easy to want to use a library or a framework for the sake of it. But we should do so while focusing on the end goal, which is, fulfilling human needs, desires, and fantasies. Anything else is just not of the same value.
This reminds me of a tweet I retweeted recently.
Coding and building is also a means to an end. Sure, it can be fun for us (it is for me) but we must not forget why we do it for. If the tool we build is not solving someone’s problem, it is not as impactful as building a tool that solves someone’s problem.
For that, we should use whatever works. Whatever solves the problem correctly, most efficiently, for the largest number of people.
This article was first posted on my website.
Posted on November 25, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.