News for hackers. Stuff that matters.
Re:YAML and Configuration Files by thayne on Saturday August 14, 2021 @03:31PM (#28183347)
> YAML isn't a configuration language or a configuration language format, it's a serialization format

I think YAML is even worse as a serialization format than a configuration format. It has too many ambiguities, implementations are too inconsistent, and many implementations are insecure by default with untrusted input.

> Using a good custom designed configuration file format instead of trying to shove things through the narrow pipe of YAML means that you have one integrated syntax that can be designed to be more readable, more expressive, and much easier to write.

I won't say a custom configuration is never the right thing to do, but I do think it rarely is. Writing a good custom configuration language is very difficult to get right, not to mention you also need syntax highlighting and other editor support for the editors your users use, libraries for popular languages so that other programs can read and write the configuration, etc. If you need something this complicated, I'd reach for using an embedded scripting language like lua (or possibly JavaScript or python) before writing a new format from scratch.

Re:YAML and Configuration Files by amirkdv on Saturday August 14, 2021 @04:10PM (#28183603)
> I think YAML is even worse as a serialization format than a configuration format.

This. I find YAML to be the least offensive option for configuration and one of the worst for serialization.

I might be misinformed, but I find it absurd that in 2021 we still don't have a default, universally available tool that supports the basic table stakes without headache:

1. core data types (number, string, etc)

2. lists, maps, and arbitrary nesting

3. comments

4. multiline strings

5. is acceptably readable

6. Just Works everywhere

YAML does get 1-5 right (specifically 3 and 4 that JSON doesn't and IMO better in 5). But then it adds a ton of complexity that has left us without a standard, safe, and sane parser implementation: anchors and references (& and *) , casting (via !!), custom data types (via !), loads of other things I don't understand.

Re:YAML and Configuration Files by MichaelMoser123 on Saturday August 14, 2021 @09:12PM (#28185372)
>loads of other things I don't understand.

also you can have multiple instances of yaml trees in one file, each one separated with -- . I think this makes it very confusing if used as a configuration language (they like to use yaml for configuration in kubernetes)

Re:YAML and Configuration Files by Spivak on Saturday August 14, 2021 @09:40PM (#28185515)
I mean sure but I’ve never seen any software actually use that feature in the wild except for “you’re allowed to concat your YAML files instead of separating them if you want.” Like I’ve never seen software require a certain number of documents in a file with different schemas.
Re:YAML and Configuration Files by MichaelMoser123 on Saturday August 14, 2021 @10:59PM (#28185920)
i saw it being used in some CI system; it was very confusing.
Re:YAML and Configuration Files by brundolf on Saturday August 14, 2021 @04:37PM (#28183747)
It's a real shame JSON doesn't have 3 and 4, because it would be so easy and it's otherwise pretty much perfect imo. No ambiguity, every value type can be identified by its first character, clean and reasonably minimal syntax.
Re:YAML and Configuration Files by bschwindHN on Saturday August 14, 2021 @11:19PM (#28186014)
JSON5 is nice. I use it for all our configuration files at work after evaluating a large list of configuration file formats. I've never really run into any frustration using it, whereas YAML, TOML, and others drive me crazy when I need to represent nested structures or arrays.

https://json5.org/

Re:YAML and Configuration Files by plusmax1 on Saturday August 14, 2021 @05:49PM (#28184208)
well there are json alternatives which fit this bill, such as HJSON.

https://hjson.github.io/

might not be as "common" but it has good implementations for many languages.

Re:YAML and Configuration Files by MichaelMoser123 on Saturday August 14, 2021 @09:02PM (#28185328)
you could allow python like comments and strip them with a regular expression substitution before parsing. Something like this. (it strips all the lines that start with whitespace, followed by #, followed by anything until the end of the line)

   cat cfg.json | sed -e 's/\s*#.*$//g' | jq .
Allowing multiple lines is more complicated, can't do that with regex alone.
Re:YAML and Configuration Files by brundolf on Saturday August 14, 2021 @09:33PM (#28185478)
There are lots of ways to implement it. The problem is that one of JSON's strengths is its ubiquity: every language under the sun has half a dozen different battle-tested parsers for it. Clients and servers and everything in-between have first-class support out of the box. You can even paste it directly into JavaScript as valid code.

If anybody short of a standards body tries to expand the spec, you lose out on most of that.

Re:YAML and Configuration Files by MichaelMoser123 on Saturday August 14, 2021 @11:04PM (#28185943)
i think you can possibly define how you want to use json for a configuration file; json by itself is not much more than javascript objects/maps, defined as a data format. I frankly don't think that you need to be too pious about standard compliance if dealing with a cofiguration format for your application.
Re:YAML and Configuration Files by SigmundA on Monday August 16, 2021 @11:34AM (#28199280)
>json by itself is not much more than javascript objects/maps

And without comments or optional quoted keys single quotes or trailing commas, which makes editing by hand more work and IMO less readable.

Re:YAML and Configuration Files by brundolf on Sunday August 15, 2021 @12:42AM (#28186319)
Editors, for one, will be an issue
Re:YAML and Configuration Files by FrancoisBosun on Saturday August 14, 2021 @11:38PM (#28186077)
What about a key named “_comment”, or something similar? Of course, the underlying software must ignore unknown keys, so it’s not a full win anyway.
Re:YAML and Configuration Files by nicklarsennz on Sunday August 15, 2021 @04:09AM (#28187019)
That might help for a general comment, but not for a comment on a specific part of the structure.
Re:YAML and Configuration Files by MaxGabriel on Saturday August 14, 2021 @09:48PM (#28185557)
If Dhall was more popular, would it meet your criteria?
Re:YAML and Configuration Files by sofixa on Saturday August 14, 2021 @04:44PM (#28183798)
HCL does all of those.

TOML is pretty close as well.

Re:YAML and Configuration Files by scrollaway on Saturday August 14, 2021 @09:09PM (#28185357)
HCL is neither acceptably readable nor does it just work everywhere. TOML is getting there though yeah.
Re:YAML and Configuration Files by petre on Saturday August 14, 2021 @11:39PM (#28186079)
I used to think that before I had to edit the ejabberd.yml config file. Now I think it's only remotely useful as a subset to use in Jelkyll headers.

Just use TOML for configuration instead.

Re:YAML and Configuration Files by account42 on Thursday August 19, 2021 @10:39AM (#28234379)
> I used to think that before I had to edit the ejabberd.yml config file.

Hey, it's still better than having to write the configuration in Erlang like you had to before.

Re:YAML and Configuration Files by dheera on Saturday August 14, 2021 @09:16PM (#28185399)
Besides the above (especially comments), YAML also has one huge advantage for configuration files and that is clean diffs.

JSON's lack of support for trailing commas messes up diffs.

Re:YAML and Configuration Files by inkeddeveloper on Saturday August 14, 2021 @10:50PM (#28185877)
If you come up with a format, call it IJW. It just works.
Re:YAML and Configuration Files by alephu5 on Sunday August 15, 2021 @04:39AM (#28187168)
Use dhall and serialise to JSON/YAML!
Re:YAML and Configuration Files by nanoscopic on Saturday August 14, 2021 @05:11PM (#28183985)
My JSON parser ( github.com/nanoscopic/ujsonin ) has these things:

0. Looks essentially the same as JSON

1. Core data types, and customizable data types can be added easily.

2. Arrays, Objects, and arbitrary nesting.

3. Comments ( both /* */ and // format )

4. Multiline strings ( by default; carriage returns are no problem within strings )

5. It is JSON with relaxed restrictions and slight addition for actual named types.

6. I've written C, Perl, and Golang implementations so far.

Re:YAML and Configuration Files by jasfi on Sunday August 15, 2021 @02:13AM (#28186595)
I like the idea of what you're doing. May I suggest a Nim port? Nim outputs C anyway, but is safe, so you'd worry less about bugs.
Re:YAML and Configuration Files by mh0pe on Saturday August 14, 2021 @11:03PM (#28185941)
My stance is that YAML is a good format for configuration management and generation -- it's wonderful at filling gaps as your deployment model increases in complexity to provide a mechanism to "render" your configuration -- much like Skylark [1] does (derived from Google's internal GCL).

YAML ends up being a powerfully declarative model [2] for the state of a data structure, rather than a straight representation, ironically often enough being used in turn for an imperative model like in Ansible [3]. Definitely friendlier than JSON. But personally, I really like YAML because it lets me compose using a traits/mixins-like model using & and *, which allows for verbose, structured configuration inputs but concise configuration files.

docker-compose YAML files extension fields [4], imo, are a great example of this type of model in action. When you leave this much pre-deserialization flexibility in your configuration representation, it makes building cool stuff like docker-compose ECS support x-aws-* extension keys [5] and other plugin system-type capabilities much more straightforward than, for example, adding a new language feature to HCL.

[1]: https://github.com/google/skylark

[2]: https://en.wikipedia.org/wiki/YAML#Advanced_components

[3]: https://docs.ansible.com/ansible/latest/user_guide/playbooks...

[4]: https://docs.docker.com/compose/compose-file/compose-file-v3...

[5]: https://docs.docker.com/cloud/ecs-integration/#rolling-updat...