3 ms·
This is good advice. Part of the difficulty is that you don't really want to write your configuration in C++ or Rust and have to recompile your whole program to
by IshKebab 3y ago
This is good advice. Part of the difficulty is that you don't really want to write your configuration in C++ or Rust and have to recompile your whole program to change something... but it is nice to be able to use a "real" language, otherwise eventually you'll have to resort to a real language anyway to generate your configuration.
The issue is - which language?
Ideally you want something embeddable, sandboxed, with good tool support, static types/hints and "normal" (not aggressively functional, 0 based indices etc.).
The only language that remotely ticks those boxes is Starlark. That's probably what I would use in future if I had this issue.
I've looked into many other options (Jsonnet, Dhall, Cue, Python, Deno, Lua, Rhai, etc.) but they all fall down in some way.
- lainga 3y agoWhat do you dislike about Lua? (having used it I have several answers already in mind)
- IshKebab 3y agoBeen a while since I used it in anger but IIRC no real array type, classes are weird, 1-based indices, kind of crummy syntax (does anyone really like `end`?), no static types (when I used it anyway), the stupid split between Lua and LuaJIT. It's definitely not the worst. It's just a little too weird to be able to write it without actually learning it, which is what you want in a config language. And 1-based indices just shows poor taste.
- lmm 3y agoI'd consider Starlark more obscure and less well-supported/documented than Dhall.
- IshKebab 3y agoMaybe. But Dhall falls into the "weird and aggressively functional" category. The syntax is obstinately weird. `let in`? Why. Just use `let`. `\(` for functions? Is `fn` too much? It also isn't a "full" programming language - it's not Turing complete, which has no real benefit as far as I can tell. Tbh it's probably one of the better options, but I can predict how my co-workers would react if I tried to get them to use it. I think they would be more accepting of Starlark.
- lmm 3y ago> The syntax is obstinately weird. `let in`? Why. Just use `let`. `\(` for functions? Is `fn` too much? It's inherited from OCaml/Haskell/etc.. I think staying consistent with that works better than trying to convert it to Algol-style, although I guess the jury is still out on new languages that do that. > It also isn't a "full" programming language - it's not Turing complete, which has no real benefit as far as I can tell. The most immediate practical benefit is that your configurations can't go into an infinite loop. Depending on your deployment model that can help avoid outages. In theory you could still create a configuration that would take a very long time to evaluate, but in practice that's a lot rarer than creating one that takes forever.
- IshKebab 3y ago> In theory you could still create a configuration that would take a very long time to evaluate, but in practice that's a lot rarer than creating one that takes forever. Yeah I'm not sure I buy it. There are much easier ways to prevent accidental infinite loops than artificially making your language Turing incomplete. Probably the most obvious is a compute budget (i.e. a timeout but deterministic).
- lmm 3y ago> There are much easier ways to prevent accidental infinite loops than artificially making your language Turing incomplete. Then how come none of them are popular in config languages? Starlark follows the same approach of being non-Turing-complete; all the other config languages I know of are either non-Turing-complete or accept the risk of running forever. > Probably the most obvious is a compute budget (i.e. a timeout but deterministic). That tends to have worse problems e.g. seemingly "safe" refactors can now break your config.