Shared Libraries – Why Sharing Code is a Practice in Benevolence and Sustainability

Posted by in Software Development, Sustainability, Web Development tagged with

Shared libraries offer quick access to solutions for common development problems. Incorporating shared libraries vetted by the developer community makes your entire codebase easier for other developers to understand and, ultimately, more sustainable. Why do the developers at Mightybyes use shared libraries whenever we can?

Shared Libraries Mean You Do Less Work

How far along would society be if discoveries like a spherical earth or the tensile strength of steel had to be constantly rediscovered? Fortunately for society, we don’t have to rediscover either of these things: Someone has done the discovery work and shared it with us so that we can build skyscrapers and not fall off the earth when sailing west.

Let’s define what we mean by shared libraries. They are any kind of code that already exists and, due to an open source license, can be freely included in your project. Most popular languages have repositories of libraries that solve common problems for that language: PHP has PEAR, Ruby has RubyGems and Javascript has jQuery or MooTools. Shared libraries can also include modules for existing software, like WordPress plugins or Drupal modules.

Using shared libraries can also mean that you do less development operations (DevOps) work. Using Bower to include libraries in your application means you can execute a single command to install a library to your codebase rather than find the URL, download the library, unpack it and move it to your codebase. Security updates to shared libraries are as easy as changing the URL from which the library is pulled or changing a version number in your Rails Gemfile or Bower’s component.js file.

Shared Javascript Libraries on a Content Delivery Network can Mean Your Site/App Loads Faster:

If you’re a web developer and you use jQuery, jQueryUI, AngularJS, Dojo or other Javascript libraries, there are several CDNs that host copies of many libraries. Google’s list of available libraries is rather limited, but CDNJS and jsDelivr are exhaustive.

The upside of using a Javascript library hosted at a CDN is that a CDN’s main function is to serve your files as fast as possible from the closest server possible using custom DNS configurations and URL patterns. An additional upside is that the browser will be making a request to a different domain. The HTTP 1.1 standard states that browsers should make no more than 2 concurrent connections to the same domain to retrieve assets. Loading assets from another domain can potentially load your site faster, though as Steve Souders points out, most browsers are flouting this standard, anyway.

The downside of using Javascript loaded from a CDN is that you are not in control of what is being served from the CDN. If the CDN goes away or cannot serve your Javascript, your app may be rendered inoperable until you can update it.

On the sustainability side of things, common libraries are often cached in browsers, which means they don’t have to be called from another server at all. They are, in effect, the virtual equivalent of ‘buying local’. For more information on CDNs and sustainability, check out my post Server-Level Sustainability: Green Up Your Hosting.

The Sharing Community

Open source software is based on the principle of sharing knowledge. If you have to solve something with code, chances are that someone else will need to solve the same thing with code too. Consider sharing your solution with the developer community. Read up on how to correctly contribute to your language’s package repository and give back to the community whose work you are already using.

Also, making your code open source is similar to putting it out to hundreds of QA staffers at once. Developers can poke and prod the internals and, if supported, use Git to submit fixes or features for faster inclusion into the codebase.

Shared libraries are not only a great resource for fellow developers in the community, but a practice in sustainability. You are helping people not recreate the wheel and leading to a better development ecosystem for other people, which ultimately enriches the developer community overall.

Mightybytes is a full-service creative firm for conscious companies and a certified B Corporation. Connect with us on Twitter, Facebook and Pinterest or fill out our contact form.