How do you know when it’s time to use a library instead of coding something yourself? Perhaps you don’t yet have any industry experience in this field or are unsure how to balance your code and external dependencies.

Not every line of code needs to be by yourself. You are not cheating when using a library instead of writing your code! There is still enough work left for you to show your coding skills when using the library. Most programs are greater than the sum of the dependencies they use – the essential part of your work is the problem it solves for the user.

Using libraries to help you with your coding task is regular for professional developers. Using code others have written enables you to solve your work faster. It is just another tool in your toolbox, like the carpenter building a window and using off-the-shelf hinges instead of smithing his own.

How do you find a library and decide you can use it in your project? I use multiple rules to determine if I want to use a library instead of writing the code myself. The first rule is to decide if I can save time by using a library – time is money! The next task is to find a library that solves my problem. You encounter a central repository for most languages where libraries are collected. Two examples are npmjs.com for the JavaScript world and rubygems.org for Ruby.

Keep in mind Dependencies also have a price. When selecting a library, make sure the library is still in development. As there is nothing worse than rewriting your application later on as the library you selected is no longer updated and has bugs in it. The more foundational a library is in your application, the more this point counts when evaluating a potential library.

The last part is to check the license of the library. Ensure that the library’s licenses do not interfere with your code’s license. Code licensing is a big topic that warrants its separate post. But in a short explanation, ignore any copyleft libraries. Using a library with such a license, you also need to use the same license for your project. A decision you are usually not empowered to make as an employee. An example of such a library is the GPL. The best case is finding a library using the MIT or Apache License 2.0 Licence.

You’ve learned a new power now, but be careful to find a good balance between writing your code and using libraries. You don’t want to replace all your code with third-party dependencies. So I would not use a library to replace only one line of code in my project. I would check if I can copy & adjust the code I found in this situation. Read this article: Should I copy and paste code from the internet for more details.

Think about your current project. Did you use a library there yet? If not, could you perhaps need one?

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.