Live data from Hacker News

YAML and Configuration Files

utcc.utoronto.ca

1–10 of 96 posts

Re: YAML and Configuration Files

#2
The solution for defining a more complicated config is to write your own config file format? I would think a custom format wouldn't necessarily be easier for others to read and write unless it came with a guide/readme, but then that's just one more thing to learn. Admittedly, I've never had to write a super complicated config file, but can anyone tell me why I shouldn't continue to use something like JSON for all of my config files?

Re: YAML and Configuration Files

#3
After resisting it for many years I've finally settled on YAML as my default configuration format.

I need a way of expressing the core data types of JSON (key/value mappings aka "objects", arrays, strings, integers, floating points and booleans) - plus comments, and multi-line strings that insulate me from complex escaping rules.

YAML does that. It's not perfect, but it's good enough. And in Python I can use yaml.safe_load() to avoid some of the more troublesome corners of the spec.

Re: YAML and Configuration Files

#4

The solution for defining a more complicated config is to write your own config file format? I would think a custom format wouldn't necessarily be easier for others to read and write unless it came with a guide/readme, but then that's just one more thing to learn. Admittedly, I've never had to write a super complicated config file, but can anyone tell me why I shouldn't continue to use something like JSON for all of…

Let’s not forget that almost every JSON parser optionally supports comments and trailing commma’s when parsing.

Re: YAML and Configuration Files

#5

The solution for defining a more complicated config is to write your own config file format? I would think a custom format wouldn't necessarily be easier for others to read and write unless it came with a guide/readme, but then that's just one more thing to learn. Admittedly, I've never had to write a super complicated config file, but can anyone tell me why I shouldn't continue to use something like JSON for all of…

Let’s not forget that almost every JSON parser optionally supports comments and trailing commma’s when parsing.

Which ones do that? I've not encountered many myself.

Re: YAML and Configuration Files

#6

The solution for defining a more complicated config is to write your own config file format? I would think a custom format wouldn't necessarily be easier for others to read and write unless it came with a guide/readme, but then that's just one more thing to learn. Admittedly, I've never had to write a super complicated config file, but can anyone tell me why I shouldn't continue to use something like JSON for all of…

Compared to yaml or ini formats, JSON is arguably harder to read and definitely harder to write due to having to keep track of brackets, commas, and/or quotes.

Ideally, a configuration file should be easy to read and write/modify by a user of the application. A lot of applications just stick with ini like formats because it meets both requirements.

Re: YAML and Configuration Files

#7
I think I get what the article is saying. I don't think they expressed it very well.

Here's a concrete example of what I think they're complaining about. From a Kubernetes Deployment manifest:

    - name: DATABASE_URL
      valueFrom:
        secretKeyRef:
          name: db-conn
          key: uri
That valueFrom.secretKeyRef.{name, key} structure is an "exploded AST" — something that in any programming language, you'd be chastised for writing out as a structural-initialization literal, because there's so much stuff there that it's easy to screw it up and forget something.

When attempting to express such a literal in most-any programming language, you'd expect to either have:

• the Java "literal factory function" approach — some static function to call, that takes either other literals, or a single literal string encoding an expression in a DSL, as arguments, and then produces an initialized value-object; or

• the Elixir "custom sigil" approach (there's probably a more popular language with this feature, but Elixir is what I know) — a macro or operator that takes in a raw string or lexemes encoding an expression in a DSL, and then codegens out to the appropriate structural-initialization literal. (Macros are better here, as incorrect DSL syntax can be caught at parse/compile time, just like incorrect syntax of the surrounding language.)

-----

To be honest, I don't think I would want YAML to support either of these. YAML shouldn't be arbitrarily extendable; a YAML document should be a YAML document, parsed by any compliant parser. (There could be some Avro-like "embedded schema" format for YAML that enables this, but that format would be better as a layer on top of YAML, rather than being part of YAML itself.)

What I would like in YAML, is support for built-in literal sugar for certain specific YAML structures.

This is different in concept from YAML having support for a type, where that type must have some 1:1 native type on the host language side for it to encode/decode to.

Instead, a "sugared structure" would involve

1. a YAML parser having a sub-parser for certain specific DSLs, where the output of this parser is a small, standardized-in-shape container structure, made out of regular YAML arrays, dicts, and scalars;

2. a YAML generator offering a configuration option to pattern-match on these standardized-in-shape structures, where recognized subtrees are swapped out in the emitted YAML for the appropriate sugared-literal representation.

Examples of where this would be helpful include: DateTimes, URIs, UUIDs, Intervals... and that's basically it.

There really aren't too many of these. The short list above represents basically the entirety of the set of types I've ever had YAML fall down on in the 10 years I've been generating/parsing YAML documents. For everything else, it works fine.

Re: YAML and Configuration Files

#8
post #5

Earlier quoted context omitted.

Let’s not forget that almost every JSON parser optionally supports comments and trailing commma’s when parsing.

Which ones do that? I've not encountered many myself.

And JSON5.

https://github.com/json5/json5-go

Re: YAML and Configuration Files

#10
Hm.

I can see where the article is coming from. Some configuration files grow beyond classical configuration and end up being more like programming. With configuration being "Put the right connection / path strings into the program, enable some subsystems/feature toggles" and programming being along the lines of, e.g., arbitrary metric transformations in a metric collector, or programmable ACLs. With some systems, I very much end up wondering why I couldn't just load lua into the system and do the transformations with that.

However, configs in json/toml/yaml come with a lot of tooling. With a custom configuration language, you suddenly need to roll your own syntax highlighting in many editors, maybe linters, pretty-printers, ... Your config can't just be computed by a configuration management system and deployed via `computedConfig | toJSON`, instead it'll be necessary to wrangle templating. And users generally know those languages.

And writing parsers is a pain. And generating parsers is also a pain. And using bad parsers is also a pain. I've worked too much on parsers.

Those are some pretty big hurdles to overcome and if you don't, the user experience just starts off worse.

Post reply on HN