7 ms·
So what's the HN consensus on the best format for config files? Is it TOML as the author seems to prefer at the end?
by crazygringo 7y ago
So what's the HN consensus on the best format for config files?
Is it TOML as the author seems to prefer at the end?
- philwelch 7y agoMy vote is yes. Most configuration doesn’t need anything more sophisticated than key-value pairs, perhaps with namespaces. INI can manage that and TOML is basically a better-specified INI.
- hardwaresofton 7y agoI can't tell if I've spent too much time on HN or if I came to this conclusion on my own, but TOML is my language of choice for configuration now. It's flexible in the right ways and sectioning of config is so important.
- h1d 7y agoNo reason to use INI over TOML. INI doesn't even have a standard specification.
- philwelch 7y agoThat’s my point, yeah. INI is the right idea but TOML is the same thing but actually specified so use it.
- bmurphy1976 7y agoThere's no white Knight here, they all suck in some way. Personally I've had decent success with yaml as simple configuration, but I would never use it as an interchange format. If you know it's caveats and you're targeting one language so you can become familiar with the parser it's serviceable.
- majewsky 7y agoIf possible, prefer what tools in your vicinity use. My team uses Kubernetes and Concourse extensively, which both use YAML, so I tend to stick with YAML since people are already familiar with it. (More recently, I've come around to prefer plain environment variables for configuration, but that only works nicely when the amount of configuration is fairly limited, say 20 values instead of 1000 values.) For my own use, I do prefer TOML.
- kissgyorgy 7y agoPerfect comment! I agree 100%.
- crdoconnor 7y agoThe main issue I had with TOML is how much more syntactically noisy it is. Equivalent files with 2-3 levels of nesting usually become at least 50% longer than equivalent YAML. More here : https://hitchdev.com/strictyaml/why-not/toml/ https://hitchdev.com/strictyaml/why-not/toml/
- meowface 7y agoThis is a different use case, I think. This example is defining content, not configuration. In this case the content is user stories. I agree for creating sequences of documents/content in this way, YAML often is nicer. But for configuration, TOML is designed to specify it in a simple and flat way, and that can be very helpful. I have some projects where I'm frequently writing and midifying content that resembles the example here, and I use YAML there and plan to keep using YAML. For most other things, I'm just doing configuration, so I use TOML. No reason you need to stick to one or the other.
- wodenokoto 7y agoMy cursory survey of config / serialisation formats concluded that nothing is close to being good. It's overly verbose, and hard to understand XML, it's no comments son, horrors of yaml or some okay format that doesn't have parsers for the languages (plural) you are using on your project.
- chucky_z 7y agoI use JSON in the end. I prefer to write TOML, then parse that into JSON. This seems to strike a nice balance between human/machine write/read. It's simple enough to reason TOML, even if it gets verbose. If I have to write YAML after 2 layers I usually write it as JSON and include the JSON in the 2nd level of key.
- edoceo 7y agoI'm still using INI files like it's 1999.
- h1d 7y agoEverything being a string is a bit of a joke now.
- mcphage 7y agoIn the scale world, HOCON is very nice. It’s a format designed explicitly for config files, and has a lot of niceties (like you can append files together and they merge correctly, so you don’t have to end up with giant config files)
- SeanA208 7y agoI agree with HOCON being nice based on personal usage but I haven't seen an in depth analysis of it. This is the canonical parser for JVM based languages — https://github.com/lightbend/config https://github.com/lightbend/config, are there many other implementations that are widely used?
- rch 7y agoThat's the one Akka uses, which probably comprises the majority of HOCON usage. I've also used the Python port without issues.
- twic 7y agoWhat's the "scale" world?
- TJSomething 7y agoI think they meant "Scala", the programming language.
- mcphage 7y agoSorry, yes, Scala. Autocorrect changed it and I didn't notice.
- rusk 7y agoI think it's horses for courses. JSON I guess is the best for interchange i.e machine to machine, but I never want to edit it by hand; XML is relatively easy to read but can be quite painful to edit raw, but it can be quite easy to develop a structures editor. I’d favour it for document persistence. YAML is fine for configuration files but I would be careful about how I apply it and would always provide it as a heavily documented templated config file. YAML when used correctly is by far the easiest to edit in the clear, with a plain text editor. With that said, I would try to get away with basic namespaces properties files first before I’d go that far ...
- geerlingguy 7y agoini if needs are crazy simple, YAML if you need a structure like JSON's but with something any human ever needs to interact with. JSON if humans aren't in the loop. TOML, in my opinion, is like a weird mishmash of JSON, ini, and bashisms. Though I have worked with it a lot less than the other formats, so YMMV.
- jtdev 7y agoSince when is JSON not human readable/maintainable??
- meowface 7y agoTry writing strings with backslashes, or adding a new line to your array and accidentally leaving a trailing comma (or accidentally forgetting it for the previous row). It's also just very visually noisy. I agree with a lot of the other comments in this thread that for human configuration: TOML > YAML > JSON > XML
- rusk 7y agoYou can edit JSON by hand but it’s not what it’s for. It’s not designed for that and it’s not really suitable for that. Theoretically you can milk anything that has nipples, but you might find the experience of milking a cat to be ... challenging
- monocularvision 7y agoBeen working more with Dhall and have really enjoyed it so far. https://dhall-lang.org/ https://dhall-lang.org/
- twic 7y agoPutting commas at the start of the line is the toe shoes of syntax.
- garethrowlands 7y agoYou can put them at the end of the line.
- peterwwillis 7y ago.ini, followed by TOML, followed by an identical implementation of some other app's config format. The biggest problem with config formats is they mislead users into thinking they understand the format. The user tries to edit it by hand, and chaos ensues. So only formats that are stupidly simple, or whose warts are already familiar and well documented, are good choices. Apache had a great configuration format. Nothing else used it (that I knew of) but you could in theory implement "Apache configs" and then people'd just have to look up how to write those, which there's lots of examples of. JSON and YAML and XML are data formats; they should only be written by machines, and read by humans. Same with protocols like HTTP, Telnet, FTP... You're not supposed to write it yourself, but it's readable to make troubleshooting easier. Data formats are nice for expressing nested data structures, but then they don't (usually) support logical expressions; at that point you need a template/macro/programming language, and at that point you're writing code, which will need to be tested, and at that point you should just write modules and use a config format to give them arguments. Every complex tool goes through the same evolution. If you care about your users, write a tool to generate configs based on a wizard. Good CLI tools do this, and it really makes life better. (It's also a great way to document all your config features in code, and test them)
- falcolas 7y agoIt's telling that the responses to this question are broad and varied. Still not a well solved problem, it seems.
- bobbyi_settv 7y agoIt's also telling that even with every other possible answer being given by someone, there's still no one who wants XML.
- panzagl 7y agonah, the XML people are just keeping quiet because no one likes hearing 'I told you so'
- davedx 7y agoJ S O N all the way.
- markmark 7y agoI say just use JSON. Everyone knows it already and it's good enough. Use a parser in your app that allows comments and trailing commas like vscode does.
- dagenix 7y agoThat's not JSON anymore, that's some custom format that's JSON inspired.
- deleted 7y ago[deleted]
- skybrian 7y agoYep. Some kind of JSON++ is where we're headed. Hopefully we can agree on a new standard someday? (No, not YAML.)
- tln 7y agoJSON5.org would be nice :)
- wwright 7y agoIf JSON did support this (and multiline strings), I think it’s unlikely anyone would reach for anything else.
- markmark 7y agoCool. It doesn't matter.
- deleted 7y ago[deleted]
- jaredklewis 7y agoI dislike json with comments or trailing commas as even if your parser can handle them, it surprises many text editors. Aside from lack of comments, the other major thing that can sometime make json a bad config choice is lack of multi-line strings.
- wdroz 7y agoFor in-house, python-only project, my way to go is to create a "config.py". Then I declare a bunch of module variables that can be overridden by environment variables as a bonus.
- deleted 7y ago[deleted]
- apple4ever 7y agoYAML for me, then TOML