TL;DR why do people pick YAML/JSON/ini/TOML/XML/plain text to configure applications/packages instead of having the configuration be defined in source files the application/package is written in? I mean, I can see some obvious reasons that pertain to particular cases:
- Your code is written in multiple languages and they all have to be able to read the same config
- The language you are using makes it cumbersome to describe data structures this way: if there aren't data literals and everything is
SomeOOInterface.add(foo)
for 100 lines it's easier and clearer to just parse a data format - Configuring a pre-compiled binary where the consumer of the thing can't just alter the source
- For security reasons you don't want the people configuring the thing to be able to run arbitrary code (from JonasH in the comments)
Just to name a few. Yet I often see these choices being made even in contexts where none of those hold: JSON configs in Javascript projects. Pip using a regular text file with an ad hoc format for dependency management in Python projects. Situations where the people writing the code and doing the configuring are the same people.
For contrast, I called out Javascript a minute ago but many Javascript tools will actually accept Javascript source files for configuration. The built-in Swift package manager has the developer configure projects in an actual .swift
file. LISP is the obvious trope-namer here: everything is data, so the division between data and code doesn't even exist.
Configuration languages vary in power but none of them are as expressive as the source language, JSON doesn't even allow comments, and there are times when the ability to perform logic/assign vars/annotate metadata/etc are useful if not necessary. The arbitrary distinction between data and code may be fine for a textbook, but it seems to break down in practice in this particular case.
So when a configuration language is being used without one of the reasons outlined above applies, is it just voodoo chicken coding based on examples where that choice makes sense for the reasons stated? Or is there something I'm missing here?
EDIT
Just discovered this gem: https://matt-rickard.com/heptagon-of-configuration