Layers are Good

Posted 3 years, 6 months ago | Originally written on 13 Oct 2020

Photo by Annie Spratt on Unsplash

I find that, invariably, code that has been thoroughly pondered over tends to organise itself into layers. For example, for most of the code I write, which runs in the shell, there will be:

  • a presentation layer, which handles commands and options and returning things to the user;
  • a handler layer, which dispatches commands;
  • a work layer, where all the main steps are visible; and lastly
  • a toolbelt layer (usually called util), which takes care of little details such as formats, conversion etc.

This list is not exhaustive but I've found it appear again and again. Having layers means that you know where various actions fit in and helps you cleanly demarcate between function and API, which you can then avail to others to hook into.

So, that's the point. Layers are good.