Configuration is Code

Code can be broken down into three things:

  1. Variables
  2. Constants
  3. Logic

The variables represent customer data, and the code expects them to change regularly, so making code configurable is limited to your constants and your logic.  

Making Constants Configurable

When we make code configurable we usually start with constants.  The idea of "hard-coded" often gets shamed and derided, but a constant is an assumption, and if we make no assumptions, we multiply the test paths and never get done testing.  The only time the "hard-coded" shame and scorn is legitimate is when the constants are littered throughout the code and not put in a common location (but this is really just good organization and doesn't affect your customers until maintenance takes too long).  However, if we are OK with making testing take longer, there are definitely cases where assumptions should be changeable. 

The program does not expect a constant to change for the lifetime of the program and makes optimizations based on that, so usually a restart is required.  A properties or INI file is really a list of constants the code lets you change, which is why changing config often requires a restart.  If you want to avoid a manual restart safely you have 2 options:

  1. Turn the constant into a variable so the code expects change
  2. Automatically stop and start a new version that has the new variables (probably waiting for a quiescent period first).

Making Logic Configurable

Logic is the most difficult part of a program to make configurable, and once you make the program logic configurable, you have a shell of a program, your configuration is a domain-specific-language (DSL) and you need to start debugging your configuration.  This has been covered well in "The Configuration Complexity Clock".  I would say that rules engines are in this camp, if they are meant to be changeable by business types.  Perhaps a safe way to make logic configurable is to limit the configurability to conditionals at specific points.  Then at least you can trace out the configurable condition before and after and not have to step through code in a language you don't have a debugger for.  

To view or add a comment, sign in

More articles by Aron Vandermeyden

  • Property: Own, Rent, and/or Share

    We in the West like to talk about property rights, but really property is mostly about responsibilities, or cost. There…

    1 Comment
  • Building Software - No Easy Options

    Our leadership has talked about build vs. buy in software development, and I'm sure they mean more than they say, but I…

    1 Comment

Explore content categories