by zvr · 3y ago · 0 comments
My preferred one, which I have not found in other languages (besides LISP, obviously): treat data as code.
This way your configuration files are Tcl code using some proc's that you have defined, but they can also include arbitrary code. In order to read them, you simply fire up a slave (safe) interpreter and get the results.
If anyone knows how to do this easily in Python, I'm all ears!
Typically the reason for not using a full-blown programming language for config is to avoid Turing creep - the tendency to want to push complexity into config in order to make the application code simple. At some point the config gets to complex it needs its own config.
I run into this temptation using Lua a lot. Lua tables are perfect for config, but it would also sometimes be so convenient to just pop on a metatable and turn it into a class, maybe a proper API, when really all I need is a table that defines constants, maybe some conditionals, arrays, a map and that's it.
host thatmachine.example.org
port 9991
dbhost server.example.org
... which I can definitely parse myself. But it's also valid Tcl, if host/port/dbhost are defined proc's!So this allows people to be able to create config files like:
set mydomain example.org
host thatmachine.$mydomain
dbhost server.$mydomain
if {$mydomain == example.org} {
port 12345
} else {
port 9991
}
I don't expect people to create huge programs in their config files, but being able to give them a "full-blown programming language" for free is sometimes desirable.