40

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

.yaml, .toml, etc?

all 47 comments
sorted by: hot top controversial new old
[-] Veraxus@kbin.social 19 points 10 months ago

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 14 points 10 months 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

[-] Telodzrum@lemmy.world 19 points 10 months ago

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

[-] atzanteol@sh.itjust.works 10 points 10 months ago

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

[-] abhibeckert@lemmy.world 14 points 10 months ago* (last edited 10 months ago)

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.

[-] atzanteol@sh.itjust.works 4 points 10 months ago

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.

[-] schaeferpp@discuss.tchncs.de 0 points 10 months ago

Somebody has to say it, so I'm taking on the duty:

If whitespace is a problem, you use the wrong editor.

[-] atzanteol@sh.itjust.works 6 points 10 months ago

Oh, yeah, nothing like telling a dba they're using the wrong editor when they're trying to configure something.

If your config format requires specific editors you're using the wrong format.

[-] vrighter@discuss.tchncs.de 2 points 10 months ago

you can write json with comments and pass it through a yaml parser. try it.

[-] jmanjones@lemmy.world 1 points 10 months ago* (last edited 10 months ago)

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!

[-] starman@programming.dev 9 points 10 months ago* (last edited 10 months ago)

TOML looks good but it's rarely used

[-] emptyother@programming.dev 1 points 10 months ago

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

[-] Paradox 5 points 10 months 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

[-] exu@feditown.com 6 points 10 months ago

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 10 months ago* (last edited 10 months 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.

[-] SubArcticTundra@lemmy.ml 1 points 10 months ago

You could use TOML. It's pretty much an extension of INI

[-] cyd@lemmy.world 5 points 10 months ago

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

[-] emptyother@programming.dev 5 points 10 months 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 10 months ago

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.

[-] negativenull@lemmy.world 5 points 10 months ago

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

[-] tony@lemmy.hoyle.me.uk 2 points 10 months ago* (last edited 10 months ago)

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 2 points 10 months ago

Thanks for the tip!

[-] emptyother@programming.dev 1 points 10 months ago

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 3 points 10 months 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.

[-] schaeferpp@discuss.tchncs.de 0 points 10 months ago* (last edited 10 months ago)

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 10 months ago

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

[-] jesterraiin@lemmy.world 3 points 10 months ago

Depends on the purpose of the software. In certain specific situations a plaintext *.txt is unbeatable.

[-] atzanteol@sh.itjust.works 4 points 10 months ago

An unstructured text document can be "unbeatable" for configuration how?

[-] jesterraiin@lemmy.world 2 points 10 months ago

The "PURPOSE" is the keyword.

If the purpose of the software is to work in closed, offline environment with Mr. NOTECH operating it via "line 5: rotations per minute; line 6: temperature in Fahrenheit" commands, then trust me, it's going to get the job done.

[-] atzanteol@sh.itjust.works 2 points 10 months ago* (last edited 10 months ago)

"unbeatable" and "get the job done" are very different claims. If you just have bare unlabeled numbers on "magic lines" in a file - sure you can work with that. But I'd hardly say it's "unbeatable" compared to "anything else" for readability and clarity. It's the type of thing programming classes have students do so they don't have to introduce libraries or other concepts.

It's very likely that Mr. NOTECH would be able to understand "TEMP_F: ###" just as easily as "put the temperature on line 6". And it would likely be MUCH easier for Mr. NOTECH to look at a config file and read back to you what the temperature setting is. Especially if they haven't worked with the software for long. As a bonus it would be easier for Mr. NOTECH to know whether the temperature should be in F or C. Or even Kelvin.

[-] jesterraiin@lemmy.world 0 points 10 months ago
[-] atzanteol@sh.itjust.works 1 points 10 months ago

I see, you're not being serious.

[-] jesterraiin@lemmy.world -1 points 10 months ago

I absolutely am. You're simply overthinking it - the scenario I provided makes plaintext *.txt perfect.

Sure, we can spend the rest of the day inventing scenarios, where Mr. NOTECH will be manipulated remotely by aliens, and what then, but that's an exercise in creativity, not a situation that needs to be taken into account.

[-] axzxc1236@lemm.ee 3 points 10 months ago* (last edited 10 months 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.

[-] lnxtx@feddit.nl 3 points 10 months ago

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 10 months ago

YAML. This is the way.

[-] RaivoKulli@sopuli.xyz 2 points 10 months ago

Normal text file

[-] Paradox 1 points 10 months ago

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 0 points 10 months 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.

[-] Andy@programming.dev 1 points 10 months 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.

[-] knobbysideup@lemm.ee 0 points 10 months ago

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

[-] abhibeckert@lemmy.world -1 points 10 months ago* (last edited 10 months ago)

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.

this post was submitted on 15 Aug 2023
40 points (95.5% liked)

Technology

55693 readers
2671 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