Dependency Management

© 2017 Morgan C. Benton code4your.life

Dependency Management

Modern software is NOT built from scratch. The unique functionality of most apps relies upon a rich ecosystem of packages and libraries that are written by other people. These packages, in turn, rely upon yet other packages. The hierarchy and collection of required packages can be extensive and complex, which gives rise to the need for package or dependency management systems.

© 2017 Morgan C. Benton code4your.life

Example

You're writing a program that has to make an HTTP request to get data from a remote location on the web. Instead of writing your own code from scratch to make HTTP requests, you would import an HTTP library written by someone else and use that.

© 2017 Morgan C. Benton code4your.life

// JavaScript example
// import request library
var request = require('request');

// use it
request.get('http://example.com/data.json')
  .on('response', res => {
    // do something with data.json...
    var data = JSON.parse(res);
  });
# Python example
# import request library
import requests

# use it
r = requests.get('http://example.com/data.json')
data = r.json()

Terminology

  • Package or Library: a self-contained unit of code usually designed to be reusable and accomplish a well-defined range of tasks
  • Dependency: a relationship between two packages in which one package requires (i.e. is dependent upon) another in order to do what it does
  • Package Manager: a type of utility software that keeps track of:
    • which packages have been installed
    • what their dependencies are
    • whether or not dependencies have been installed
    • the versions of each package that are installed

© 2017 Morgan C. Benton code4your.life

Example Packages

  • Making HTTP requests
  • Filesystem interaction/management
  • Interaction with various database systems
  • Testing and test-driven development (TDD)
  • Authentication and Authorization
  • Collection utilities
  • Application frameworks

© 2017 Morgan C. Benton code4your.life

Package Managers

© 2017 Morgan C. Benton code4your.life

Language Package Manager(s) Package Repo
JavaScript npm, yarn npmjs.com
Python pip, easy_install pypi.org
R built in, packrat cran.r-project.org
Ruby gem rubygems.org
PHP composer packagist.org
Java maven search.maven.org
Go dep golang.org/pkg

Choosing a Package

© 2017 Morgan C. Benton code4your.life

  • Packages are typically discovered via web search, Stack Overflow, or in the official documentation
  • Frequently there will be multiple packages that can perform the same or similar functionality. Choosing the right package is important. Key factors include:
    • when was it written?
    • how often is it updated?
    • how many times has it been downloaded?
    • are bugs being reported, and if so, addressed?

Where are Packages Stored?

© 2017 Morgan C. Benton code4your.life

In general, packages get downloaded from the internet and stored on the developer's computer in one of two places:

  1. Globally: there is a specified location on the system where all programs written in a given language have access to them
  2. Locally: downloaded packages are stored in a subdirectory of the current software project and are only accessible by that one project

Learning to Use a Package Manager

© 2017 Morgan C. Benton code4your.life

Learning to use a package manager is basically a required skill for doing any sort of modern development. There is a learning curve involved, but the productivity gain is well worth the investment of time and energy necessary to learn it.

Dependency Management

By Morgan Benton

Dependency Management

Introduction to the concept of dependency management in computer programming. Example code in a variety of languages is provided to demonstrate dependency management in a variety of programming languages.

  • 1,134