this post was submitted on 15 Aug 2023
30 points (96.9% liked)

Technology

59201 readers
4129 users here now

This is a most excellent place for technology news and articles.


Our Rules


  1. Follow the lemmy.world rules.
  2. Only tech related content.
  3. Be excellent to each another!
  4. Mod approved content bots can post up to 10 articles per day.
  5. Threads asking for personal tech support may be deleted.
  6. Politics threads may be removed.
  7. No memes allowed as posts, OK to post as comments.
  8. Only approved bots from the list below, to ask if your bot can be added please contact us.
  9. Check for duplicates before posting, duplicates may be removed

Approved Bots


founded 1 year ago
MODERATORS
 

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

.yaml, .toml, etc?

all 30 comments
sorted by: hot top controversial new old
[–] Telodzrum@lemmy.world 15 points 1 year ago

IDK what the best is, but I know for certain it’s not YAML.

[–] Streetdog@lemmy.world 14 points 1 year ago

TOML. Easy on the eyes and easy to grep and filter out comments.

I really like the way Fail2Ban handles it with a .local config. The default doesn't need to be backed up, and the .local is most minimal and concise. I'm unaware of any other programs doing it that way. I have scripts that either execute sed or tee -a to config files, after making a backup copy of the original.

[–] Veraxus@kbin.social 13 points 1 year ago (1 children)

If you want the file to be directly human readable/editable:

  1. TOML
  2. YAML

If you never need to look at it or edit it manually:

  1. JSON
[–] vrighter@discuss.tchncs.de 8 points 1 year ago

I hate yaml with a passion. for stuff such as ansible it becomes an uneditable mess (one copy and paste away from destroying the whole file)

luckily, yaml is a superset of json, so you could just write json and feed it through a yaml parser and it'll work

[–] atzanteol@sh.itjust.works 10 points 1 year ago

I don't know which is the best, but yaml is the worst.

[–] starman@programming.dev 7 points 1 year ago* (last edited 1 year ago) (1 children)

TOML looks good but it's rarely used

[–] emptyother@programming.dev 0 points 1 year ago (1 children)

TOML does look good. Wow! I havent looked at it at all before.

[–] Paradox@lemdro.id 2 points 1 year ago

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

[–] emptyother@programming.dev 5 points 1 year ago

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.

[–] darganon@lemmy.world 5 points 1 year ago (4 children)

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.

[–] tony@lemmy.hoyle.me.uk 2 points 1 year ago* (last edited 1 year ago) (1 children)

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.

[–] darganon@lemmy.world 1 points 1 year ago

Thanks for the tip!

[–] negativenull@lemmy.world 1 points 1 year ago

If you have a problem, and use XML to solve it, you now have two problems

[–] schaeferpp@discuss.tchncs.de 1 points 1 year ago* (last edited 1 year ago) (1 children)

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.

[–] darganon@lemmy.world 1 points 1 year ago

I mainly work with windows, and powershell works great with xml.

[–] emptyother@programming.dev 0 points 1 year ago (1 children)

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.

[–] atzanteol@sh.itjust.works 2 points 1 year ago

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.

[–] cyd@lemmy.world 4 points 1 year ago

.el (Emacs Lisp), nothing beats using Lisp to configure a Lisp environment.

[–] axzxc1236@lemm.ee 3 points 1 year ago* (last edited 1 year ago)

For my last self-made program, I just wrote a config.py, and call import config from other code files and write my config in Python.

[–] exu@feditown.com 3 points 1 year ago (1 children)

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...

[–] JoeClu@lemmy.world 2 points 1 year ago* (last edited 1 year ago)

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.

[–] RaivoKulli@sopuli.xyz 2 points 1 year ago

Normal text file

[–] Paradox@lemdro.id 1 points 1 year ago (1 children)

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

[–] frezik@midwest.social 1 points 1 year ago

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.

[–] lnxtx@feddit.nl 1 points 1 year ago (1 children)

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.

[–] titey@lemmy.home.titey.net 0 points 1 year ago

YAML. This is the way.

[–] knobbysideup@lemm.ee 1 points 1 year ago

That depends on if a human is reading/writing it, or a program.

[–] Andy@programming.dev 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.