What is the best file format for configuration file?
What is the best file format for configuration file?
cross-posted from: https://programming.dev/post/1743099
.yaml, .toml, etc?
What is the best file format for configuration file?
cross-posted from: https://programming.dev/post/1743099
.yaml, .toml, etc?
IDK what the best is, but I know for certain it’s not YAML.
If you want the file to be directly human readable/editable:
If you never need to look at it or edit it manually:
I don't know which is the best, but yaml is the worst.
Uh no, the worst is a tie between XML and JSON.
XML because the syntax is hard to read and even harder to write, and JSON because you can't do comments. WTF.
XML is a bit verbose but otherwise easy to understand. JSON5 supports comments.
And neither requires me to explain weird formatting nuances to devops engineers.
YAML is a pain to read (lists of structures are very messy), can't be auto-formatted, and is full of weird "gotchas" (Norway, errant tabs, etc.) if you don't do things "the right way."
Requiring the use of whitespace in formatting is wrong. End of.
you can write json with comments and pass it through a yaml parser. try it.
I instant exit on XML conf files. I have no idea how to parse the info, maybe I should. But there are too many tags and my eyes instantly glaze over when I see it!
TOML looks good but it's rarely used
TOML does look good. Wow! I havent looked at it at all before.
Makes certain levels of nesting painful
You can say this is a design choice, and you shouldn't ever go too deep in config, and I'd agree, but it is a limiting factor to be aware of
For simple stuff, INI is pretty good.
I must admit I've written stuff that uses a JSON config file, but I might finish implementing YAML instead. Any day now...
Agreed about INI for simple stuff. Not good for arrays and nested things though. Usually use binary for that type of config (with clear documentation). Most binary config files I use are plain old C structures. I'm not a web person so no need to make the config plain text.
You could use TOML. It's pretty much an extension of INI
I like xml, but it isn't the easiest to read.
I hate yaml with a burning passion. At least with JSON you can compress it all down.
If you have a problem, and use XML to solve it, you now have two problems
A compliant yaml parser will read json, as they're essentially siblings.. so just write your configs in json and they'll work, if you dislike yaml.
Thanks for the tip!
I'm no fan of XML. It looks messy and the schema is difficult to write, imo. XML works best as a markup language.
YAML could have been okay if it were stricter with what they consider strings, and used tabs instead of spaces.
Using whitespace was a mistake. I know all the kids love it but it's just wrong. I've never had as much difficulty explaining json or xml to users as I have yaml.
We seem to have something in common: there is a serialisation form, we strongly dislike. But what I cannot understand is: why the heck would anyone torture anyone else to read or even write XML? XML is the absolutely worst configuration language I can imagine. I mean: when is something an attribute, when a tag on its own? What is even a list? And don't forget to include a full HTTP URI for the namespace, otherwise the tag is not defined.
By the way: all valid JSON is valid yaml as well. So in theory, you can use yaml as JSON with comments.
I mainly work with windows, and powershell works great with xml.
.el (Emacs Lisp), nothing beats using Lisp to configure a Lisp environment.
JSON if it also has an online schema, and a reference to it in the JSON file. That way some editors can check for errors and hint to the user about it.
But the good old flat text-data, the ini format is consistent, readable, and easily understandable by less-technical users.
That one which I can automate.
I mainly use Ansible or Puppet. So YAML isn't that bad if you fully understand it.
Puppet language sux IMHO.
YAML. This is the way.
Depends on the purpose of the software. In certain specific situations a plaintext *.txt is unbeatable.
An unstructured text document can be "unbeatable" for configuration how?
For my last self-made program, I just wrote a configpy, and call import config
from other code files and write my config in Python.
Normal text file
I like how elixir approaches it: configs are just elixir script files that have a module for some common conventions. Gives you a lot of power, and no goofy new syntax
That works if you have a small, disciplined team. As the team grows and it becomes harder to enforce standards, config files that are run through the language compiler easily get filled with programming statements that shouldn't be in a config file.
It’s like yaml but simple, consistent, untyped, and you never need to escape any characters, ever.
Types and validation aren’t going to be great unless they’re in the actual code anyway.
That depends on if a human is reading/writing it, or a program.
Assuming you can trust whoever wrote the config file, I prefer if it's executable code.
Not really fussed about what language. The point is it's really handy to have simple logic checks like a basic if statement on an environment variable. I also like being able to split my config files up into multiple files - maybe with an environment variable to check which files will be loaded in.