this post was submitted on 15 Aug 2023
29 points (93.9% liked)

Technology

34790 readers
580 users here now

This is the official technology community of Lemmy.ml for all news related to creation and use of technology, and to facilitate civil, meaningful discussion around it.


Ask in DM before posting product reviews or ads. All such posts otherwise are subject to removal.


Rules:

1: All Lemmy rules apply

2: Do not post low effort posts

3: NEVER post naziped*gore stuff

4: Always post article URLs or their archived version URLs as sources, NOT screenshots. Help the blind users.

5: personal rants of Big Tech CEOs like Elon Musk are unwelcome (does not include posts about their companies affecting wide range of people)

6: no advertisement posts unless verified as legitimate and non-exploitative/non-consumerist

7: crypto related posts, unless essential, are disallowed

founded 5 years ago
MODERATORS
 

cross-posted from: https://programming.dev/post/1743099

.yaml, .toml, etc?

all 35 comments
sorted by: hot top controversial new old
[–] [email protected] 29 points 1 year ago
[–] [email protected] 21 points 1 year ago (2 children)

There is no best. It depends on the application

[–] [email protected] 1 points 1 year ago
[–] [email protected] 1 points 1 year ago (1 children)
[–] [email protected] 7 points 1 year ago

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

[–] [email protected] 13 points 1 year ago (1 children)

The one already being used by the project.

[–] [email protected] 8 points 1 year ago (1 children)

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.

[–] [email protected] 5 points 1 year ago (1 children)

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.

[–] [email protected] 3 points 1 year ago* (last edited 1 year ago) (1 children)

Yup, YAML is a terrible data format, but for a configuration format that you completely control, it works well. Your parser only needs to be good enough to read the configs you create.

Likewise, JSON is a pretty bad config format due to strictness in the syntax (no optional commas, excessive quotes, etc), but it's pretty good data format because it's pretty easy to parse.

TOML is like YAML, but it has fewer corner cases so it's pretty easy to learn completely.

Though anything is superior when it's already the status quo on a project.

[–] [email protected] 1 points 1 year ago

I don't know dude, with YAML treating the word no as a Boolean and having like 6 types of multi line strings I'm really inclined to disagree with the "fewer corner cases" part. It's like waaaaaaaay less corner cases. Imagine pasting the ISO abbreviation for a country as a Boolean value.

[–] sylver_dragon 12 points 1 year ago

A well documented one.

[–] [email protected] 7 points 1 year ago (1 children)

Definitely not yaml. It's spec is horrible.

Toml is pretty nice though.

[–] [email protected] 10 points 1 year ago (1 children)

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?

[–] [email protected] 10 points 1 year ago (2 children)
[–] JonnyRobbie 4 points 1 year ago (1 children)

Thie essentially boikls down to "quote yur shit". Yes, it can be frustrating if a language superficially allows you to use unqoted strings with the promise that it will inteligently interprets that. It's like parentheses in arithmetics. If you are not sure or if you are not competent in a language enough to predict the order of operations, use parentheses. The same with strings and quotes in yaml.

[–] [email protected] -2 points 1 year ago (1 children)

... or just use another tool where you don't even have to think about this problem.

[–] [email protected] 1 points 1 year ago

I get that JSON is intuitive and a huge improvement over XML, but I still find it verbose.

[–] [email protected] 4 points 1 year ago

Very educational.

[–] [email protected] 5 points 1 year ago (1 children)

.ini has never let me down.

[–] [email protected] 3 points 1 year ago (1 children)

It's a bit janky with spaces and things, but the simplicity is insane!

[–] [email protected] 1 points 1 year ago
[–] [email protected] 4 points 1 year ago

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.

[–] [email protected] 2 points 1 year ago

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.

[–] [email protected] 1 points 1 year ago

nix

This post was sponsored by NixOS gang

(jokes aside, json is king. Yaml is a pain in the ass)

[–] [email protected] 1 points 1 year ago

UCL and HCL are interesting, but YAML is more widely supported.

[–] [email protected] 1 points 1 year ago

https://nestedtext.org/

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.

[–] [email protected] 0 points 1 year ago

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.

[–] BitSound 0 points 1 year ago (1 children)
[–] JonnyRobbie 2 points 1 year ago (1 children)

Meh, at that point, you may as well use python.

[–] BitSound 1 points 1 year ago

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.

[–] [email protected] 0 points 1 year ago