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?
Not xml
There is no best. It depends on the application
Agree 100%
How would it depend?
Some applications don't have enough config entries to warrant support for nested entries
Some applications need variable-length data, and some even variable-length lists
Some applications don't care about having fast read/write times or a small memory footprint and can do with more complex formats that require the use of third-party libraries
Some embedded applications (e.g. AVR) don't have access to a whole lot of libraries
The one already being used by the project.
Yup. If I have to pick one for a new project, I'll go with TOML unless there's a reason to pick something else. I like that it's simple, while also having a bunch of features for when the project grows.
Pretty much same here. With Spring stuff I still use YAML because TOML doesn't have first class support yet. If TOML is an option I don't have to go too far out of my way for them I go for it.
YAML has too many foot guns. It's still less annoying to read and write than JSON though. Properties files are okay but there doesn't seem to be an agreed upon spec, so for edge cases it can be confusing.
Agreed. YAML is a pain to edit manually, to ensure that all the tabulation is correct and the parser does not choke. JSON is passable, but you must be mindful about the brackets. XML is too verbose and duplicative. INI files are just good enough.
That's why I like TOML. It's basically INI, but it has more structural features if you need them. Most of the TOML files I use look just like ini files.
YAML is fine if you use a formatter. JSON's ok to read but a pain to write imo. INI if it's simple.
A well documented one.
JSON is overly verbose and doesn't allow comments. Please do not use it for anything that humans frequently need to read or write.
YAML is a syntactic minefield. Please do not use it for anything ever.
How is it syntatic minefield? I find it at least more reasonable than XML. The comment feature is nice to have.
yaml is susceptible to things like the Norway problem: https://www.bram.us/2022/01/11/yaml-the-norway-problem/
There's also a lot of stuff that can go wrong with deserialisation that make it a tricky dependency for security purposes. I like how yaml looks and it's obviously much better than XML, but it had those potential problems
Definitely not yaml. It's spec is horrible.
Toml is pretty nice though.
I hate table definitions in TOML with a passion.
I like YAML. I guess that's because I don't need to build parsers for it. What's your worst complain about it?
.ini has never let me down.
It's a bit janky with spaces and things, but the simplicity is insane!
Yup yup!
I'd say a file that you can open with a simple text editor is convenient, so it can be a simple .conf/.ini, more complex are .xml/.yaml that you can still edit in vim/nano but can be cumbersome.
But as others say, it all depends on your app...
Toml is about the same as ini files at least with what I've worked with
I really dislike when indentation is a part of the syntax (like in YAML). Apart from that it depends on the requirements of the project.
How able Lua?
It's a programming language, so you can do fancy stuff, or you can just use it as a regular key value file. You can also safely enable/disable features so you only need to allow the subset of Lua that you need.
It works really well for things like editor configuration (see neovim), and it's especially nice if you already use Lua as a plugin language or something.
UCL and HCL are interesting, but YAML is more widely supported.
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.
nix
This post was sponsored by NixOS gang
(jokes aside, json is king. Yaml is a pain in the ass)
If you use protobuf/gRPC anywhere in your application, text format protobuf. Writes like JSON, but with a clear schema, a parser that already exists in most languages, and has comments.
Json
.txt
Overall, JSON5 (having comments and end-of-line commas is a big reason I got into YAML).
I suffer with YAML, but use it pretty heavily. It also has the and & operators which I use fairly heavily, and it fits well with the Markdown + YAML I use, but I hate that whitespace indenting with a passion.
Occasionally, I look at Nickle (https://github.com/tweag/nickel) and KDL (https://kdl.dev/) and I get really tempted, just haven't made that jump.
Meh, at that point, you may as well use python.
I like Python and use it a lot, but Dhall has several guarantees that Python doesn't. If you hand someone clever a Python interpreter, they can and will find a way to run rm -rf /
or what-have-you, no matter what safeguards you put in place. Dhall also guarantees that it will terminate, which is pretty useful if you're embedding it in something else. In Python you could pretty easily accidentally or purposefully get into a while True
loop.