Libraries Provide, Applications Consume

In software development, a simple framework to keep in mind that clarifies how to write certain code is that libraries provide and applications consume. Libraries should useful and reusable in most contexts, therefore it should play nicely with other code and be more or less agnostic. Applications on the other hand are intended for end users and make different trade offs—the code is written for a user not for other code or contexts.

A simple example to highlight the difference is error handling. A library should encapsulate and provide all errors that can be thrown by code in the library so that it’s easily discoverable and can be handled by downstream callers. Applications on the other hand need to catch errors so they can provide feedback to users or log them appropriately—they consume errors produced by the code in their application.

See also:

  • This is easily apparent in Rust error handling libraries: thiserror for libraries and anyhow for applications