Skip to content

Instantly share code, notes, and snippets.

@divarvel
Last active June 3, 2019 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save divarvel/36aa1d1fd10c21919f3524f1842cccd3 to your computer and use it in GitHub Desktop.
Save divarvel/36aa1d1fd10c21919f3524f1842cccd3 to your computer and use it in GitHub Desktop.
Config as Code? Yes, but cleanly. Try some Dhall

There's always a point where we are tempted to replace config files (json, toml, yaml), with just code. It's handy, we get structure and abstraction, we can have little helper functions, proper comments (I'm looking at you, JSON). It's especially useful when the config is verbose, or very common. The flip side of going the config as code way, is that we lose a lot: updating config is updating the application itself (not very 12 factor compliant, and not user-friendly as well when using compiled languages). Worse, some arbitrary side effects can sneak into your configuration step. Another issue is that it becomes really hard to read or analyze config files without launching the application itself (bye linters, bye dependency checkers, bye organization-wide metrics). If you want to do that properly, it means building a way to output generated configuration, building a sandbox to run the application, and a few other unsavory contraptions.

All this issues stem from two things:

we have removed the boundary between application logic and configuration
we use a Turing-complete language to author configuration

Thankfully, those two characteristics are accidental rather than essential to config as code. Dhall is a language designed to be used for config as code without compromising on what make config files great: clean separation between code and config, as well as predictable behaviour. It provides all the abstraction you need to author config files in a comfortable and flexible way (types, interfaces, functions), while being not Turing-complete (guaranteed termination) and allowing restricted side effects.

In this session, we'll see how we can author config files with Dhall, how we can read them from an application, and how we can use Dhall to generate JSON/YAML, in order to configure applications not able to use better technologies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment