This is the web site of Denis Defreyne, a software engineer living in Berlin.

Logging and caching are (usually) acceptable side effects

Good software development practice includes the elimination of side effects. Side effects make it hard to reason about the implementation.

While eliminating side effects is a worthy goal, two types of side effects are commonplace, and often expected:

  • Logging. For example, HTTP GET requests are expected to be idempotent, i.e. two requests should the same outcome as one. However, two requests (as opposed to one request) will yield two log lines, rather than just one.

  • Caching. For example, a HTTP GET request could modify the cache, causing subsequent requests to be considerably faster.

These two types of side effects are so commonplace that they might not be called side effects, but rather intended primary effects.

Exceptions exist for both types of side effects, however. A (very small) list of examples:

  • In garbage-collected languages, logging can allocate a potentially large number of extra log messages, increasing GC strain, increasing memory usage (which can lead to OOM situations), and increasing swap usage, leading to measurable changes in performance and availability.

  • Caching as a side effect enables side-channel attacks.