Yaml is huge unintuitive PITA, I recently spent multiple hours figuring out the best way pass CLI arguments to a k8s cronjob via yaml. I only managed to solve the weird error messages after I stumbled upon the stackoverflow post linked in the webpage https://stackoverflow.com/a/21699210
> There are NINE (or 63*, depending how you count) different ways to write multi-line strings in YAML.
I hate to be the YAML defender, but I strongly believe that all of YAML's block and flow scalar types are necessary and that YAML's string handling is one of its killer features. Sometimes you need C-style string escaping with "" and sometimes you need verbatim strings with '' (same use-cases as verbatim string literals in programming languages, eg. for regexp.) Sometimes you need collapsed newlines and stripped trailing newlines (writing a description for your blog post in YAML frontmatter) and sometimes you need preserved newlines (embedding other languages like Markdown or Bash in a YAML document.)
A language like YAML should let you represent different types of strings in a way that's still human readable.
A "configuration file" is simply a valid script that is executed in a safe interpreter.
some_key: >4
This text has to be indented by 4 spaces.But that's entirely situational. A yaml snippet containing my list of groceries is not code.
Yaml doesn't have to be classified as code to be testable. "We should have tests for our configuration files" is perfectly reasonable.
I’m amazed this is even a question. Of course it is! It’s explicitly defined as an interchange format. Its only purpose is as code.
> In an informal setting.
What formal settings are we supposed to be satisfying?
> If you are, for example, writing documentation, please refrain from doing so.
I respectfully decline this request.
> But that's entirely situational. A yaml snippet containing my list of groceries is not code.
> Yaml doesn't have to be classified as code to be testable. "We should have tests for our configuration files" is perfectly reasonable.
I mean this with kindness and sincerity, if a little incredulity: maybe your definition of code is ambiguous and warrants some clarification. To me, this isn’t a holistic definition but it certainly seems like a relevant starting point: if it has a syntax specification that machines can use, it’s code.
1. a systematic statement of a body of law
2. a system of principles or rules moral code
3. a. a system of signals or symbols for communication
b. a system of symbols (such as letters or numbers) used to represent assigned and often secret meanings
c. coded language : a word or phrase chosen in place of another word or phrase in order to communicate an attitude or meaning without stating it explicitly
4. genetic code
5. instructions for a computer
Relevant to the discussion here are points 3 and 5. I would argue json, yaml, and xml, would be called code under points 3 as well as 5.There are a lot of valid complaints about YAML, but I still reach for it when I really only need a barebones configuration file.
Could not disagree more strongly and it seems many others in software agree, based on this comment section and the original article.
> It's easy to serialize complex objects to, and comes bundled with Ruby's runtime.
I don't know that Ruby support is why it's widely adopted. Ruby is common in some spaces, but not a wildly popular language at all.
I honestly think some popular project (maybe Docker Compose or something from HashiCorp?) used it for a config file and then everyone else started doing it too.
Requires some amount of legibility out of the box due to whitespace requirements.
Can store complex data structures (and even direct JSON).
Allows comments.
It comes bundled with something. Question answered.
TOML may get more popular due to Rust.
I think these are the main things that push yaml. In particular, being clean and simple for straightforward data is a big plus: configurations are often just key-value lists of ver small strings, having something that is readable and looks simple helps a lot.
And for anything that needs more finesse, switching to XML or JSON is often supported.
Most programming languages are written to impress other programmers. We need a programming language which is trivial to learn, which you couldn't ever use to write a webserver, but you would use it to configure one.
Here's what I want. Something that is more readable than JSON, so either TOML-like or YAML-like, but without executable code or any of that nonsense. On top of that, a schema definition file (think XSD) that asserts facts about the structure of the config, using a theorem prover like Coq or Idris.
This way, we get nice configs, but within a restricted space.
I think the YAML as code comes from using YAML as a DSL and writing an interpreter.
A benefit is that knowing yaml may at least give you the ability to configure the system, even if a project is built using an unfamiliar programming language.
Sometimes people that can read code, like most of us here, don't get bothered by tokens like "{" or some of the more complex hierarchical structures but for someone that doesn't want to learn/understand code YAML is much more appetizing.
Most of the complaints against YAML are really complaints against complex systems (Kubernetes, CI pipelines) which use it as their interface. The rest of the problems can be solved by quoting your strings.
YAML works perfectly well if it is (1) used for the right use cases rather than as a substitute for code and (2) paired with a linter or parser which handles its quirks.
How do I get all of YAML's millions of other users to quote all of their strings?
What about programmatically generated YAML?
Also, you're entirely ignoring two other major issues: meaningful whitespace (making YAML hard to read and write) and multiple ways of doing the same thing (making it confusing).
- For your own projects use yamllint, put it in your CI pipeline, and your pre-commit hooks. You can forbid the use of flow sequences like [ and {, require quotes, and forbid truthy values for bools.
- USE JSON-SCHEMA. It works on YAML.
- For programmatically generated YAML just generate JSON and call it day.
- If you have a tool that for some reason requires YAML but not JSON then don't write YAML. Write your config in $programming_language and only dump the YAML at the end. Troposphere is a Python library for CloudFormation JSON that embraces this idea.
- Don't template YAML files (or JSON for that matter). Again just use variables in your programming language of choice and then dump. Helm is an abomination and the authors should be ashamed of themselves. Ansible had the common sense to only allow templates in the values instead of at the file level.
That is, I suppose, a strike against YAML: we just "downgrade" to JSON and never have any issues.
Regular expressions are a good example. Developers seem to hate them. I find them easy and intuitive, and I'm not the sharpest tool in the shed. However, I will take some care to commit some stuff to memory and make some notes. That's it. When you know what characters are magic, know what the special characters mean, they're extremely straight-forward except when they're very complex.
Same thing with YAML. It's got a couple of rough edges, but the complexity carries its weight, and most of the difficulties go away if you bite the bullet and memorize it. Just commit those block chomping operators to memory, it doesn't hurt that much, then you can get on with your life and quit complaining about YAML and make it work for you.
It's very good for non-technical people to edit because they are allergic to symbols and quotes and brackets and making sure things match. YAML's syntax let you write like you're a CEO sending agenda notes to a subordinate. You can easily switch between line-per-item and brackets-style and you do so whenever the readability is improved by doing so. It's highly intuitive somehow. You can pretty much turn someone into a config-editor just by showing them an example file, especially with syntax highlighting.
I strongly disagree. Being whitespace sensitive it's stupidly bad for non-technical people.
I don't like YAML for several reasons, to be honest I'd prefer an .ini based config setup or BSD styled "option=variable" config file paradigm. But I hate/despise/loathe the fact that YAML files are whitespace sensitive. That's a horrible choice. I hate python for it too, and avoid it's use whenever possible.
People have strange trouble with delimeters. They put commas inside the closing quote, (e.g. ["hello," "there"]) because I guess that's how they were taught in English class somehow. They forget a bracket and then can't figure out how to fix it because the tools are no help. They start putting in excess braces like they're some type of Simon Says: [{"hello"}]. I guess I can't be critical -- this is a lot like how I write CSS. But whitespace makes more sense to a lot of folks because it just "looks right".
TOML is a decent format because it does use whitespace for delimiting -- but only newlines. It gets verbose if you want to represent large amounts of deeply-nested data, though.
Per the YAML docs [0], "Creating a fully compliant parser has proven almost impossible." Pretty much every YAML parser out there is going to have its own idiosyncratic subset that it handles. That doesn't make the _files_ not-YAML.
(This does make YAML a horrible data exchange format. No argument there!)
Also, JSON has a similar condition [1].
[0]: https://github.com/yaml/yaml-grammar [1]: http://seriot.ch/projects/parsing_json.html
Yaml has parts that broaden its use cases, but I'm slightly surprised that json+yaml comments isn't a more widespread thing.
I've been using Ansible a lot recently. I like it a lot, most of the time. Its configuration files are YAML + Jinja2 templates + Python expressions. It works fine for the basics but when you push it quickly devolves into madness.
e.g. I had a task like this:
- set_fact:
foo_bar: >
{{ item | map(attribute="something") | rejectattr("bar", "none") | flatten | select is any }}
Can you spot the error? The block scalar header `>` was missing the hyphen `>-`. YAML helpfully added a newline to the end of the template output. Python helpfully interpreted "False\n" as `true`.I'm starting to think I should write Python modules for anything complex.
Actually that's pretty nice compared to what we actually got:
Building SQL queries by concatenations strings, however, should get you arrested for negligence. If you need a query builder, then you need a query builder.
[1] http://mikehadlow.blogspot.com/2012/05/configuration-complex...
It's mentioned on the site as an alternative to Yaml. Recently watched (~half of) this intro to it: https://youtu.be/fR_yApIf6jU
No: Body: Wants: To: Write: – YAML - https://news.ycombinator.com/item?id=17360088 - June 2018 (71 comments)
Nobody Wants to Write YAML - https://news.ycombinator.com/item?id=24638883 - Sept 2020 (1 comment)
Ultimately, I don’t think it would be possible to avoid the sorts of problems people run into in any configuration language unless you have a strict type system on the config itself. But strict type systems on config have been tried and end up causing their own distinctive problems.
In the end people will complain about whatever their interface is to a complex system. They will always make errors in configuration and that will always be annoying.
If I have to choose one, I’d choose the first one. It really does fix most of the warts. But there’s probably a fundamentally better approach somewhere out there if you can find it.
Ironically the file format for sublime highlighting plugins is in YAML.
https://github.com/hjson/sublime-hjson/blob/master/Hjson.sub...
Is there really a better alternative? JSON is a horrible format for configuration, KDL is a cute idea in theory but in practice it makes me want to gouge my own eyes out, CUE is... weird, XML and INI should've been dead for years and TOML is just INI on meth...
At least JSON and YAML are somewhat interoperable (JSON is valid YAML* and converting YAML to JSON is trivial) and have native support in most modern languages...
* with some caveats
Its message stirs passions, it is written in the very formalism it talks about, and presented in a so unusually cumbersome way that it triggers the same kind of response (or questions) a surrealist setup do (essentially boiling down to: "why the f...?").
Thank you, it was delightful to experience.
When you have a flexible standard which allows people to do something in many different ways, it defeats the entire point of there being a standard...
- First there were bash scripts kicked off by cron
- Then there was Oozie which was XML and not those messy scripts
- Then there was Airflow which was code and not that messy XML
- Now there is Argo/etc. which are Yaml and not that messy code
The endless cycle of code-to-config-to-code continues.
Using strongly typed programming languages (like how Pulumi uses TypeScript) also works well.
Then I tried to use it in one of my own projects and immediatly ran into issues. Mostly that it was difficult to judge what data structures you would get.
Massively different syntax could result in the exact same structre, slight changes could make it something completely different. I just really didn't like it :/
(Kidding.)
(Mostly.)
I think the general rule here is to use the simplest format necessary.
YAML is good as a concise configuration description language, but using it as a serialization format for general data should be avoided at all costs.