Use a Library or DIY?

This question comes up a lot when planning (and working on) programming projects. Should I use a library for this feature or just write the code myself? It can be applied to almost every section of a project. There are so many libraries and frameworks out there that you can probably get a prototype working just by gluing together third party code. There are a few factors to consider while making the decision.

How much time do you have to implement the feature? – If you don’t have the time, use a library. It’s better to add a dependency and possibly bloat the program than miss a deadline trying to do it yourself. You can always rewrite that feature later if you really want to remove the library.

How important is the feature? – If the feature is very important to the success of the project it might be best to use a popular, heavily tested library. Writing it yourself could introduce bugs and security risks not present in the third party code.

How unique is the feature? – The available libraries might not suit the needs of your project or the feature’s requirements. If you would spend a lot of time extending the library with project-specific code you should consider writing only what you need.

How large are the libraries you are considering? – A library might add a lot of bloat to the program. Unless the library is very modular, writing what you need might be the best option.

Do you have the knowledge required to build the feature? – If you don’t, the time needed to learn the information has to be factored in during the decision making process. Also, gaps in your knowledge could have a big impact on code quality and efficiency.

Will it be fun writing the feature? – If most of the above questions point to doing it yourself, consider whether or not you’ll enjoy working on it. Sure, sometimes it’s necessary to write code that isn’t fun. If the project requirements demand doing it yourself, but you’ll hate doing it, it might be best to just do it. However, if you get to make the call, can do it yourself, and think it would be fun why not do it?

Libraries have a lot of benefits. They can be easy to use, well tested, mature and fast to integrate. On the other hand, they can be bloated and have too many features for your needs. Why add a bunch of unnecessary code and another dependency to your project when you’re only going to use a fraction of it? Of course there are exceptions to this rule, like if you don’t have the time to do it yourself.

Doing it yourself can have many benefits too. It can be a good way to learn about the topic, reduce bloat by including only the required features and be optimised for the project’s needs. Of course, it’s almost always more difficult and time consuming to write a feature yourself than to use a library. Also, that code is bound to have more problems than a library’s which has been developed and used for a long time.

Looking at libraries before deciding to write your own can give you ideas about the system can be implemented. Even if you decide against DIY, you can learn a lot by just studying a library. Looking at the source code later on could teach a lot about the system. There are many factors to be considered before deciding to write your own code. A library can be very beneficial and inspirational whether if you DIY or not.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s