7 ms·
Why wouldn't you use Python as your configuration language?
by fridental 4y ago
Why wouldn't you use Python as your configuration language?
- lytedev 4y agoI believe you may want a non-turing complete language for strict configuration. But sometimes, as you indicate, you want VERY dynamic configuration. But I would argue then that such logic goes in your application itself and is not in fact part of your configuration.
- jcookeak 4y agoFor one thing, Dhall is not Turing complete. You can also freeze imports to prevent supply chain hacks, so it is much safer in theory. They have a great writeup on their safety here: https://docs.dhall-lang.org/discussions/Safety-guarantees.html https://docs.dhall-lang.org/discussions/Safety-guarantees.ht...
- chrisjharris 4y agoMost of the time with configuration files, you want to be able to do at least basic validation on the config without having to run the whole piece of software. Python has no native typing, so there's nothing to stop the user from creating a configuration file where, for example, they have set a field that is intended to specify a port number, as a string. This error will become obvious when you run the software (and it presumably fails some way in) but for some use cases this is too late. With dhall you can specify that the field for the port number needs to not just be an integer, but be a natural number, so you're able to catch plenty of config errors nice and early, and can go some way to validating the config in isolation from the software it's intended to be used for.
- Groxx 4y agoHave you seen Starlark? It's not too far from that, but safer in a number of ways: https://github.com/bazelbuild/starlark https://github.com/bazelbuild/starlark
- q845712 4y agoI said this above as well: ytt (https://carvel.dev/ytt/ https://carvel.dev/ytt/) lets you embed starlark into valid yaml, among other cute tricks for managing biz-logic in configs.
- Groxx 4y agoHuh. Clever strategy, though I'm not sure it'd be something I'd use... It is a pretty decent "take your existing yaml and make incremental improvements" setup though. Rewriting all of your config from scratch is rarely an enjoyable experience.
- Blackthorn 4y agoSometimes you just explicitly want to output text or a structured format, but you'd rather have a template language do it because it being a lot less powerful actually makes it easier to write close to the output format.