λ Tony's blog λ
The weblog of Tony Morris

# Configuration versus Code

Posted on January 9, 2011, in Programming

Sometimes I’ll be working away when a colleague will make some distinction between “that which is configuration” and “that which is code.” In all cases, it turns out that this distinction is premised on a having a very narrow understanding of solving software problems. That can’t be good.

When we write compositional code using techniques such as referential transparency, the distinction between configuration and code completely evaporates. I wish to emphasise this evaporation, so I will restate it: it is not possible to determine which is configuration and which is code, except when using very sloppy problem solving habits, no matter how much we wish to save the thesis. I made this emphasis because I have even seen people accept that the delineation disappears, then in the very next breath say something to the effect as if it were still there. Brains are fascinating machines. I digress.

Let us suppose a Haskell program, though, the language is unimportant to this point. We only need to examine the type signature:

application :: IO ()

If we need some form of “configuration”, such as a possible String value with a “default”, we pass it as such:

application :: Maybe String -> IO ()

Then the body of application will apply the default: fromMaybe "default string". Easy right?

You might have multiple configuration values and not necessarily with the type String. Now of course, since we are using Haskell (and not XML!), we can give our configuration values a type! Here is an example:

data Initialisation = Initialisation {
ioWait :: Int
, performance :: Speed
}

application :: Initialisation -> IO ()