Ask HN: What do you like to see in a configution file format?

2 points by logicallee ↗ HN
I'm working on a home automation system anyone can set up for themselves with one central configuration file[1]. What do you like to see in a configuration file format?

[1] based on this: https://github.com/robss2020/computerplayverysexymusic

16 comments

[ 5.5 ms ] story [ 42.5 ms ] thread
1. Comments

2. I like the separation of data and the program and am not the biggest fan of using a full scripting language as a config file (sometimes popular js, php, and lua)

Bonus: Some way to specify variables for reusable values, not a deal breaker though.

Bonus 2: Not having to learn a radical new config file format.

a big plus one for both these items mentioned. and annoyance I've encountered with some configuration files is the lack of a built-in comment line so I can communicate in line with the configuration decisions to a future user.

Your comment about variables for usable values reminded me that it would be nice if the configuration file parser could reference other variables and sections of the configuration file to avoid repeating oneself in the same configuration file. for example, if the configuration files describing a fleet of virtual machines, it would be very handy to define small/medium/large system types with varying RAM, CPU counts, and disk layouts, then reference just the small, medium, or large type throughout the configuration file.

>Your comment about variables for usable values reminded me that it would be nice if the configuration file parser could reference other variables and sections of the configuration file to avoid repeating oneself in the same configuration file.

How do you suggest specifying a variable?

As someone who's dealt with configuration files for many years in formats such as ini, xml, json, yaml, etc. not to mention all of the custom binary configuration file formats such as the Windows registry, or other system bespoke configuration file formats, in the end what works best for me and possibly most people is a configuration file format that is human readable and maintainable with a simple text editor or even basic command line tools.

I'm glad most of the industry has got away from the binary blob for configuration file, but I don't see great advances that the new configuration file formats such as TOML or others I'm not aware of provide above a basic yaml or json file.

my personal preference is yaml followed by jason, and from what I understand the ability to convert between those two formats is because both have feature parody with the other. I might be wrong, but as long as a system can ingest either of those I find it my preference to use that over something else. maybe if I had a third place file format it would be ini, but it has a lot of restrictions on the type of data structures it can convey.

Thank you. I agree, I think yaml is the right choice for this application. Thanks for your thoughts in both comments you posted.
- legible: readable and editable without special programmes

- documentation generator: aside from "human readable", have tooling support for documentation generation

- syntax/plausibility checking: tooling support for consistency checks

- UTF8 support

- variables: specify and populate placeholders

- modularisation: compose configurations out of reusable modules

- templates: something like #define in C

- concise: json, yaml and xml are too verbose imho. Maybe make use of special characters like ,!() etc for syntactical brevity

- unambiguous: indentation, capitalisation, the type of quotes etc shouldn't be syntactically relevant

- pluggability: APIs & libraries that allow using the language in my programmes

Thanks, these are great tips.

>concise: json, yaml and xml are too verbose imho I'm very surprised you include yaml in this. It doesn't seem to require me to use any syntax except a colon to separate the name from the value. (and optionally indentation to specify when something is logically a child value). How can that be too verbose? What would be a less verbose version?

You and others have all mentioned variables and placeholders to avoid repetition. How do you suggest specifying a variable?

> unambiguous: indentation, capitalisation, the type of quotes etc shouldn't be syntactically relevant

since you say types of quotes shouldn't be relevant how do you suggest I differentiate a generated image from a named one? I was thinking of making it:

module_image:"images/module.png"

to specify the path if the user created their own image, or allow them to generate one using:

module_image: generate

if they want the script to generate one using the module name, or they can follow generate with a prompt in quotes like this:

module_image=generate "keywords to use for image generation"

This would mean there are three formats module_image: would support depending on whether and where quotes are used. Without using quotes to differentiate, how would you suggest I let the user ask the script to generate the image for them rather than naming the location of the image?

Thank you for your feedback.

tl;dr: I don't know. That's why evening after evening I go on the internet and hope somebody smarter than me will solve humanity's problems.

Reflecting on my remarks, I think I had large configurations in mind as they occur in kubernetes or terraform which can be tens of pages.

> How can that be too verbose?

I meant that yaml indentations eat up screen space, every attribute needs to go on a new line and is terminated by a colon, which seems redundant since the newline already delimits attributes. If you ever have written a large k8s deployment descriptor, you'll know that yaml is not the right language for describing complex configurations.

> How do you suggest specifying a variable?

Variables should probably be set outside the template, eg. reference environment variables or be set in INI or properties files... which makes them parameters rather than variables but potato potato. The template could then reference variables by a special notation eg. $myvar or following a naming convention eg. vMyVar.

> how do you suggest I differentiate a generated image from a named one?

I worded that poorly. I think parsers get too hang up on the details. '"`’«» etc could be all syntactic equals, unless a good use case justifies different meanings. Eg. bash has different meanings for different types of quotes. The parser probably could infer when a statement is a literal vs. a reference simply by checking if the reference exists.

> Thank you for your feedback.

If you put the specification for your configuration language on a git repo then interested parties could open issues and discuss specific topics.

Thank you for your thoughts. Since the app itself doesn't have users yet I think it might be overkill to start discussing the configuration on its own git repo! However I will take everything you wrote into consideration and I appreciate the time you took to respond. I especially liked the clarification about screen space, which I'll use to ensure I don't nest things more than 1 max 2 levels.

By the way, although it is too much to open a repo for it, what do you think about this UML for how I structure the parts of the application?

https://imgur.com/a/FUTphwa

(I already have the parts working.) The user talks to the voice recognition engine which is a subprocess of the voice recognition server. In terms of what to do (actions to take) the voice recognition takes configuration files and dispatches scripts. To give feedback to the user the voice recognition server also communicates via a web interface. (i.e. the user could have this web interface open and see what actions the home automation server is taking, which scripts have been launched etc.)

Do you think this structure is all right for a configurable voice recognition automation server app?

I don't actually want a configuration file most of the time, I want to describe the whole thing as real code. Give me a JavaScript entry point instead.
Interesting. Can you give an example? The configuration file we're talking about is what actions the home automation server could take in regards to hearing certain keywords. Suppose you want to add a keyword and the corresponding functionality (what should happen when you say the keyword). How would you like to add it using a JavaScript entry point? (For example what to do in response to a keyword to play a certain playlist.)

    switch(keyword) :
        case "unlock":
            return unlockDoor();

Or something like that. what you're talking about is less like a config and more like a program.
CUE (https://cuelang.org)

Why would you want to build a new format over using an existing one?

Is it a good idea to still force a single file once the configuration reaches some sufficiently large size?

Thank you for the link. It's a new application so I didn't really mean "new format" so much as what you would like to see the configuration itself support. (Maybe I should have said: "when you find that an application has a configuration file, what are the characteristics of that file in terms of functionality and format that you like to see - what do you like to be able to configure in an application and how do you like to be able to configure it using a configuration file, in terms of both structure and functionality?")

You mention "Is it a good idea to still force a single file once the configuration reaches some sufficiently large size?"

If it is not limited to a single configuration file what do you suggest is best practice for which one(s) should be loaded?

Lots of programs have a --config flag(s) or well known files.

CUE naturally allows splitting config & schemas into multiple files.

You can split by purpose, whether CUE or traditional formats. Start with one until it makes sense to split for understandability