Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Really wish people would just bite the bullet and do configuration as code instead of trying to make all these config petlangs.


I appreciate that the ts/js ecosystem seems to be moving in this general direction.

Lots of config.json is being replaced by the nicer config.ts.


I really dislike it when a turing-complete language is used for configuration. It almost always breaks every possibility to programmatically process or analyze the config. You can't just JSON.parse the file and check it.

Also I've been in projects where I had to debug the config multiple levels deep, tracking side-effects someone made in some constructor trying to DRY out the code. We already have these issues in the application itself. Lets not also do that in configurations.


That's why Starlark exists.

You need something between JSON/YAML and Python/JavaScript.

A config language makes the possibility space small.

It also makes it deterministic for CI and repeatable builds.

It also makes it parallelizable and cacheable.

Don't use your language for config. People will abuse it. Use a config language like Starlark or RCL.


> It almost always breaks every possibility to programmatically process or analyze the config. You can't just JSON.parse the file and check it.

Counterpoint: 95% of config-readers are or could be checked in with all the config they ever read.

I have yet to come across a programming language where it is easier to read + parse + type/structure validate a json/whatever file than it is to import a thing. Imports are also /much/ less fragile to e.g. the current working directory. And you get autocomplete! As for checks, you can use unit tests. And types, if you've got them.

I try to frame these guys as "data values" rather than configuration though. People tend to have less funny ideas about making their data 'clean'.

The only time where JSON.parse is actually easier is when you can't use a normal import. This boils down to when users write the data and have practical barriers to checking in to your source code. IME such cases are rare, and most are bad UX.

> Side effects in constructors

Putting such things in configuration files will not save you from people DRYing out the config files indirectly with effectful config processing logic. I recently spent the better part of a month ripping out one such chimera because changing the data model was intractable.


This is what's nice about Pkl, you define a schema as a Pkl file, you define a value of that schema as a Pkl file that imports the schema, `pkl eval my file.pkl` will do the type check and output yaml for visual inspection or programmatic processing, but keeping it to one file per module means that I almost never obsessively D-R-Y my Pkl configs.

Actually that's not the biggest benefit (which is tests for schemas) but it's nice to have the “.ts” file actually log the actual config as JSON and then the app consumes it as JSON, rather than importing the .ts file and all its dependencies and having weird things like “this configuration property expects a lambda.”


I still have to see a JS project where the config for each tool could not be something simple like `.toolrc`. We could have some markers to delineate plugins config.

Instead, there’s a another software in the configuration of sample projects, instead of just using good code organization and sensible conventions.


When Python projects used that approach (setup.py files) that meant to just know what a package's dependencies were, arbitrary code had to be run. Now it's pyproject.toml


pyproject.toml calls into a build backend which is... Python.

It is good to have a simple, declarative entry point to the build system which records declarative elements of the build. The non-declarative elements of the system are configuration-as-code.


My preference is towards simpler formats like:

  option value
Easy to edit and manipulate. JSON and YAML is always a nightmare if it's user facing. As for ansible, I'd love to see some scheme/lisp variants.


then how you distinguish between string "52" and number 52 ?

Keep adding more edge cases and you have something resembles JSON


Why do you need to differentiate between the two as an input? It’s config, not random data. If you have

  email test@example.com
  logo-size 100
  background #adadaf
  modules auth
  modules db
  modules files
The only reason to have special token here is if you multiple line values. Types are not a concern.


i don't. and neither my perl-based softwares. there should not be the possibility whereas a given parameter can have both string or a numeric value too at the configuration level which the user interfaces with - as of the "real-world analogy" programming paradigm suggests. json and stuff still do have their place but in a lower, machine-to-machine layer.


Exactly. Emacs Lisp is an existence proof that this can be done well.


You beat me to it!

And for those that haven't taken a look at it, the "customize" menu and everything it supports is silly impressive. And it just writes out the results out, like a boss.*

* Obviously, it has a lot of "don't edit below this line" complexity to it. But that doesn't change that it is right there.


Config as code suffers from two big problems:

- Turing completeness means that you have to deal with the halting problem, meaning you can't statically ensure that a program ever completes. This is really shit when dealing with config, one buggy while loop or infinite recursive function and stuff just grinds to a halt with no good way of debugging it. Having this problem at the config level might mean that your program never even gets to properly start up, so you never get to setup the logging / otel or whatever you usually use to catch those problems.

- Normal programming languages have side effects and are therefor insecure! They can usually read and write files anywhere, open sockets, send traffic over the internet, etc. These are all properties you don't want of a config language! Especially if you can import code from other modules, a single import statement in a "config file" is now a huge security risk! This is why "npm" keeps having security nightmares again and again and again.

So what you want from a config language is not the same thing as from a programming language, you want as much power as you can get without "Turing completeness" and without any "side effects". That's the reason we have stuff like HCL and whatever the article used as an example.


This year I started using an SQLite file specifically for config values

Have used everything from Json to Cue and in-between. Tired of the context switch. Need to use SQL anyway. Fewer dependencies overall required.


Curious - how do you version the config?


I'm guessing they version a SQL file


Yes. Git log is a handy thing for versioning.

I never relied on it for developer notes. Just arguing semantics in those cases.


Yes, though languages need to develop and provide restricted execution modes for "configuration as code" for security enforcement.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: