Apps optimize

Poll: Do you prefer pre-made or roll your own libraries?

Developer Justin James uses pre-made libraries when possible to save time and effort. Do you prefer pre-made or roll your own libraries, or perhaps a little of both?

Something I see in the development industry fairly frequently is the habit of developing custom code libraries for scenarios where there are off-the-shelf libraries available. I understand the motivation behind this behavior; many times, using the available libraries would require significant changes to an application or workarounds to work as needed. At the same time, there are significant time benefits and reliability advantages to using a pre-made library. I've been shifting to using pre-made libraries whenever possible simply to save time and effort.

J.Ja

Keep your engineering skills up to date by signing up for TechRepublic's free Software Engineer newsletter, delivered each Tuesday.

About

Justin James is the Lead Architect for Conigent.

17 comments
apotheon
apotheon

I always prefer third party libraries "when possible", and so should everyone else who isn't just playing around to explore new programming techniques. The problem is defining "possible" for your particular circumstances. In my case, I need a third-party library to at least fit the following criteria: 1. open source, so I can adopt and maintain or modify it if needed, and be more likely to get responsive help from the "official" maintainer 2. copyfree license or public domain, so I never have to worry about licensing entanglements caused by non-copyfree licenses (this means no GPL, no LGPL, no Apache License, no proprietary, and so on) 3. well-designed, obviously -- by someone who knows something about the particular field in which the library applies (especially important for stuff like security libraries; authentication, cryptography, et cetera) 4. clean code, so I can understand its internals, and some combination of good API design and documentation so I can understand how to use it 5. provides what I need, without providing too much more than what I need so that needless complexity will not introduce problems I would like to avoid Most of the complaints I see in this discussion about problems using third party libraries are about not being able to keep their functionality up to date and get bugs fixed in a timely manner -- problems which do not apply to open source libraries any more than they apply to libraries you write yourself. One or two complaints are about not being able to make changes to third party libraries as easily as you can do so with libraries you write yourself, which is silly, as long as you adhere to the fourth requirement in my list above; even your own source code essentially becomes foreign source after a few months of doing something else, after all. When there isn't something that fits all my requirements, I end up having to write my own, of course. That's the point at which the "when possible" fails. edit: Y'know, the entire history of human progress is about how innovative people build on the work of those who came before them. We all use someone else's work in everything we do. I find it frankly shocking that the idea of using third party libraries, when available libraries meet our needs, is at all controversial.

JohnOfStony
JohnOfStony

When it comes to using pre-made libraries, there are two factors to consider, (1) does a pre-made library routine exist which performs the function I want and (2) how long will it take me to find it? I generally find that writing a routine myself has two benefits: (a) it does exactly what I want and (b) I learn more about programming with a wider variety of routines to write. If a routine is simple, it's usually quicker to rewrite it than to hunt for an existing equivalent. If the routine is complex, it will always be more difficult to understand someone else's code than your own (or code written to your own company's standard) so when it comes to maintaining a pre-made library routine as the needs of the application change, it may be more time consuming to edit a pre-made library routine than to edit one with which you are familiar because you wrote it. Another factor is speed. The code I write is speed-critical and often general purpose routines are not optimised for speed. e.g. in an If ... then ... else ... endif situation, do you use the VB Iif() function or multi-line code. I've done speed tests and found that multi-line code is faster than Iif(). It's easier to optimise my own code for speed than someone else's.

maszsam
maszsam

Some things are way easier to do yourself. By the time you figure out how the library works you could have done your own. Other things like a date picker, using JQuery pays off. Also doing things with WordPress gives you that "Me too" look unless you do your own templetes. For server side user input validiation probably want to use a libray. Testing on your own could potentially leave you liable for client damages if your code gets cracked/hacked. Do my own JS validation client side. Its a joke, as in have to look at it as usless and test everything serverside anyway, but 99.9% of users are not malicious so it speeds up the procress most of the time.

mattohare
mattohare like.author.displayName 1 Like

I insist on good documentation and a test suite that makes it bulletproof as possible.

Jeff_D_Programmer
Jeff_D_Programmer like.author.displayName like.author.displayName like.author.displayName 3 Like

I'll use pre-made libraries only if the source code is available. As a "clean-up" consultant, I have had multiple times in the past decade where a "blackbox" library incorporated by a previous developer did not function as expected / desired, which then required removal and/or replacement to the tune of several thousand $ of wasted time and energy.

333239
333239 like.author.displayName 1 Like

The danger of depending on 3rd party libraries is when they stop being supported, say if the 3rd party company/organisation goes out of business or decides to concentrate on something else. When the next version of the OS or development tool comes out, the library could require modification to work with it and then you're faced with the large task of moving to another library or writing your own from scratch. I won't use any 3rd party library unless I have the source code. Yes, they can save a lot of time in the short term but you can get into a lot of "technical debt" which could cost you considerably more in the long term.

beaverusiv
beaverusiv

Haha, this is exactly the problem Adobe stated they had with getting Flash to work in 64bit especially on Linux. Up until a little while ago Flash used third party libraries that they had no control over and of which were only 32bit. They had to then write it out and I'm guessing (hoping?) they then created their own library that better suited their needs and could increase efficiency and decrease bugs.

coloncm
coloncm like.author.displayName 1 Like

I don't have a problem with libraries that experienced developers have volunteered countless hours collaborating for a cause of new engineering technologies. I try to stay away from reinventing the wheel. Open source libraries and COTS/GOTS software have undergone extensive QA with a cause versus a cost in mind. Only two cautions: 1) check whether it's being supported and 2) check its currency/date of development. This is the only way you'd know if they have been maintained using the latest technologies (unless you decide to join them). Too big? Use only what you need. Don't know how to do that? Perhaps, you shouldn't be using it, anyways.

anil_g
anil_g like.author.displayName 1 Like

It all depends on your situation and goals. Of course, we'd all love to use reliable mature pre-made libraries with the exact feature set and API that suits us. Why wouldn't you? Saves time and money and can bring in expertise, because we can't all be the best at everything. But I just hate trying to debug someone else's library. You lose the time benefit and I guess the fact that you're debugging shows you didn't get any maturity/reliability either. And as someone else says, the more bloat you add the worse your app gets on a number of fronts. So you've got to balance up what's important for each development and the quality of the libraries on offer. I'm prefer my own stuff in many situations. I'm even wary of jQuery, for instance, because of bugs or workability problems that I've encountered, even though many web sites are built by default from jQuery, but I answered the poll as "use pre-made whenever possible", because if possible that will save time and should bring in maturity. I don't get what @jarzola said: never use library for core - not good design? Just don't get that comment. Every library is important, core or not, and needs to be reliable and efficient, all of them, all of the time. Either you've got a library that's fit for purpose (so use it) or you haven't (so don't).

Owsleyskid
Owsleyskid

My current project involves automating the integration of gas well production charts. Instead of putting the charts on a turntable & following the pen trace with a stylus, then entering the data into Excel reports, we're going to use a webcam to read QR codes with meter ID info off labels, then extract the red or blue ink pen traces, do the math, & put the results into a DB. I'm using pre-mades for the QR decode and the webcam & mySQL interfaces. A few hundred $ instead of a couple weeks of coding.

Realvdude
Realvdude like.author.displayName 1 Like

I use a combination of all three. Quite often my rolled libraries extend and or encapsulate thrid party libraries; one bonus being that you can sometimes replace third party libraries without losing the interface. I've used open source also; simple libraries from all sorts of sources and complex ones from mature projects.

irperez
irperez like.author.displayName 1 Like

When you are a consultant, speed is of the essence, use premade libraries if you can find them. However, if you are building a product and what you are building is CORE to the product, I believei in building your own. This can really bite you in the butt if you get a lot of volume or usage. This was part of the reason for the downfall of MySpace. They used a third party social API and couldn't modify it for their needs and it cost them. You have to choose which are APIs are core and which can be 3rd party and not worth spending time on.

jarzola
jarzola

I guess it depends on what you are relying on. I usually roll my own, but if there is general purpose library that I need for speed then I'll use that library. I will never use a library that the core functionality of my app rely on. That's just not good design. Never rely on an external library to run your business. For example, I would use a third party for some pdf manipulation, or a specific calculation that does not change, but I will never use a library to say... convert my objects into xml. That is something that needs to be handled in house or it will bite you later.

Slayer_
Slayer_ like.author.displayName 1 Like

It usually works out better than have a third party one and not being able to fix bugs or add features. But we usually avoid DLL's cause they often require Regsvr to be run as admin, which causes a UAC prompt during updates, confusing users.

beaverusiv
beaverusiv like.author.displayName like.author.displayName like.author.displayName 3 Like

I have a problem with prebuilt libraries when they have too much features. When I compare a simple website I was given to redesign and saw it was 1MB in size, I decided to scrap the entire codebase and start fresh (it wasn't too complicated), my end code was more modular and 150KB in size. I prefer small, light libraries that do what they do well, especially if they are not open source and debugging may be hard.

bboyd
bboyd like.author.displayName 1 Like

My firmware programs never include anything used for modules. Of course I'm not programming big things. Just interfaces, motion control and IO. I think some people think that they are modular because the use "all" the modules. ./sigh