Should you use a library when only a tiny part of its functionality is relevant to your application? Or would you be better of in writing the needed code yourself?
Writing the code yourself instead of using the library would make the code more straightforward, and you would not need to invest time in learning the library. And we all know that documentation for such libraries is usually not very complete. And the next person to work on the application would need to learn & understand the library as well.
It is a nice feeling to write everything you need in your application yourself. But it also requires a lot of time. So when you can save time by using the complex library, I would go for it. The time-saving point is especially relevant in a professional setting when you can invest the saved time in other areas of your project.
Another aspect to think about is that implementing the solution the library solves yourself is only uncomplicated at first glance. When you start implementing it yourself, you realize that it also handles many edge cases, which you now need to understand and address. And when you write the code yourself, you may also have more bugs you need to fix in the future.
Generally, I try to use a library instead of recreating the functionality myself. But this advice comes with some exceptions. Mainly because each library I integrate causes additional work in the future and makes maintenance of the application more complex later.
Of course, if the library you want to integrate only consists of ten lines of code, then I think it is not worth integrating it. But in this case, you have a reasonably good overview of what happens and can quickly write something similar. In such situations, I’m often reminded of the left-pad library accident. In such cases, it is perhaps better to copy part of the code see Should I copy and paste code from the internet? for details and what to look out for.
This topic is a sub-topic of my last blog post (When should I be using libraries rather than figuring out how to code it myself?) so everything I write in there is also relevant here. But generally, I would recommend using a library. I hope this post provided you with value and you liked reading it. I would appreciate it if you signed up for my email list never to miss another post.