Christopher Angelico

Programming DIY Dilemma

Friday, June 24, 2016

Originally posted on my LinkedIn page on January 29th, 2016.

The age old question a programmer will face many times in his life is "Should I use pre-written code for this or write it myself?" I started thinking about this as a more simplified version of the question presented in an article I read called "License an engine or create your own?" by Dietmar Hauser. Much like the topic of the article there are many pros and cons to using code or even a library instead of writing it yourself.

Starting with pros we have the fact that it saves you time...well slightly, I'll touch on this later, but the time you save from not having to write it may be lost later from a few cons I mention later. If the code is part of a library it maybe be maintained and updated by someone else offloading the need for you to tweak and refactor the code yourself. Lastly, if its publicly available code and widely used, there may be lots of useful documentation on it and how to best implement it.

On the other hand the cons for using pre-written code is that you need to fully understand how it works to make it work with your own code. Not having a full understanding of a piece of your game or program can lead to a ton of headaches down the road all of which may waste more time than you saved not writing the code yourself. If the code is part of a library the changes made to the library over time may be out of your control and counterproductive to your needs. Also if only a small part of the library is being used, then you have more resources than you need and as another article I read, "Avoid adding a new library to the project" by Irina Zamogilnaya, has shown there are many reasons why adding libraries that are not essential is a bad idea. Lastly a flip side to the last pro I mentioned previously is if the code is instead not well documented. Like the first con, if you don't fully understand how the code works you're going to run into problems later on and if you're working with a team things can get even more complicated as now everyone needs to learn how to interact with this code even if it's not well understood or documented.

So to answer the initial question "Should I use pre-written code for this or write it myself?" the answer is it depends. Is it a crucial piece of your game or program? Is it used more than one place? Is it coded poorly or not well documented? Is it small part of a large library? If the answer is yes to any of these questions, then the answer is you should probably write it yourself.

No comments :