Dependencies

There is an inherent structure to code that is often ignored. Some pieces of code depend upon other pieces of code to function correctly. This dependency establishes a relationship, and these relationships have real consequences for your program.

Functions

Interestingly, these relationships exist across all levels of programming and all programming languages. These dependencies come into play with just a few lines of code,

Looking at this code, we can see that the return value, z, does not depend on y. This means that we could theoretically skip 10*2 because the result doesn’t impact the program. Some languages exploit this relationship to avoid doing unnecessary work. It’s surprisingly tricky to get right, but it can be done!

Modules

This relationship exists at the file level too. Using Java syntax, you might have these classes,

The compiler likely needs to compile A before it compiles B. However, it can exploit the fact that C doesn’t depend on either A or B, and compile C in parallel.

Packages

This trend continues as your program adds dependencies to external libraries. Depending on what language you are using, you might have a file that lists out libraries that your program requires.

These relationships start getting complicated because those libraries often depend on other libraries. And sometimes you need library A and library B, and they both need different versions of library C. Resolving this is not trivial.

Applications

Some relationships are not even explicitly mentioned in the code. If your application requires a database or 3rd party service, then these relationships only exist when your application is running.

Nevertheless, it is the same underlying dependency. One piece of code needs another piece of code to function.

Etc.

All of these dependencies are mostly invisible. IDE’s hide module dependencies by folding away the import statements. Compilers and linkers deal with finding all the different pieces for you. Package managers put all the configuration in a file separate from the code. And runtime dependencies are barely even visible to begin with.

By ignoring them, we are both laying traps for ourselves and losing out on some of the possibilities.

Next