9 ms·
>In those cases, I would rather have XML config files than undocumented binary blobs as config files. False dichotomy. Better than XML and binary blobs: * JS
by SomeCallMeTim 10y ago
>In those cases, I would rather have XML config files than undocumented binary blobs as config files.
False dichotomy.
Better than XML and binary blobs:
* JSON (assuming everyone knows what this is)
* YAML [0]
* Lua tables (if you're already using Lua as a scripting language; Lua started out as a configuration language after all)
* INF format [1] (not my favorite, but pretty easy to parse and much better for humans to read than XML)
* Any of the above compressed with a gzip compatible compression (if size matters, though it rarely does these days)
Even Protocol Buffers [2] are better than XML, though at that point it becomes a "documented binary blob". But as long as the spec is shared, the format can easily be read by just about any programming language.
[0] https://en.wikipedia.org/wiki/YAML https://en.wikipedia.org/wiki/YAML
[1] https://en.wikipedia.org/wiki/INF_file https://en.wikipedia.org/wiki/INF_file
[2] https://en.wikipedia.org/wiki/Protocol_Buffers https://en.wikipedia.org/wiki/Protocol_Buffers
- andrewflnr 10y agoGP is obviously not stupid enough to think that XML and binary are the only options. Their whole point seemed to be that they've seen enough binary blobs in practice that even XML was a welcome step up.
- flukus 10y ago> JSON (assuming everyone knows what this is) The new .net uses json, it's awful. No comments allowed and it get's pretty unreadable when you have nested configuration elements.
- ivl 10y agoI seriously think the lack of comments is a deal breaker for JSON config files for me. At least with what I'm doing now. I find myself changing configs a ton, and I love being able to simply change which blocks are commented to get what I want, without having to dig anywhere.
- SomeCallMeTim 10y agoI agree...and I found a Gulp plugin that lets me pre-strip comments from my JSON files as part of the build process. So I use JSON-with-comments, but the app only sees the stripped files.
- piaste 10y agoVSCode uses comments for every line in its settings.json file. I guess they figured it may not be correct JSON, but since they aren't sending those particular JSON files anywhere it doesn't matter?
- Perseids 10y agoJSON5 [1] is an extension to JSON that allows comments, multi line strings, additional commas at the ends of lists, and more. It has become my preferred config file format. [1] http://json5.org/ http://json5.org/
- DiabloD3 10y agoAnd instead of Protobufs, Cap'n Proto [1], which was started by one of the principal author behind Protobufs, to fix all the flaws in Protobufs. [1] https://capnproto.org/ https://capnproto.org/
- int_handler 10y agoYou can use Protocol Buffers for configs without having to serialize them in its binary format. Protocol Buffers has always had its own text format [0] and now a JSON mapping [1] as well. The proto text format is actually more flexible and less verbose than JSON since it does not require the outer enclosing set of braces and quotes around all the keys and has support for comments. Here are a couple of examples of config files using the Protocol Buffers text format: * Bazel CROSSTOOL: https://github.com/bazelbuild/bazel/blob/master/tools/cpp/CROSSTOOL https://github.com/bazelbuild/bazel/blob/master/tools/cpp/CR... * SyntaxNet: https://github.com/tensorflow/models/blob/master/syntaxnet/syntaxnet/context.pbtxt https://github.com/tensorflow/models/blob/master/syntaxnet/s... [0] https://developers.google.com/protocol-buffers/docs/overview#whynotxml https://developers.google.com/protocol-buffers/docs/overview... [1] https://developers.google.com/protocol-buffers/docs/proto3#json https://developers.google.com/protocol-buffers/docs/proto3#j...
- chriswarbo 10y agoI've always considered YAML to be far too complicated. There are many overlapping/redundant syntax rules for doing the same thing, lots of ways to mess up parsing, etc.
- crdoconnor 10y agoTrue, but if you turn those "features" off and swap out implicit typing for explicit typing it becomes a much simpler language. This is what I ended up doing: https://github.com/crdoconnor/strictyaml https://github.com/crdoconnor/strictyaml
- chme 10y agoI am missing a config file format / parser&generator lib that preserves every comment and format (empty lines, etc.) after a read/write cycle.
- SomeCallMeTim 10y agoI've written that for Lua files. And I've seen it for XML, to be fair.
- moosingin3space 10y agoI'd say TOML [0] is the best because it can be a very simple key=value structure, but also supports very detailed, nested structures. It has a 1-to-1 correspondence with JSON, but is more friendly for configuration (comments are a huge help!) [0]: https://github.com/toml-lang/toml https://github.com/toml-lang/toml