this post was submitted on 06 Sep 2024
62 points (73.8% liked)

Programming

17450 readers
139 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 1 year ago
MODERATORS
62
Why YAML sucks? (self.programming)
submitted 2 months ago* (last edited 2 months ago) by heikkiket to c/programming
 

I feel that Yaml sucks. I understand the need for such markup language but I think it sucks. Somehow it's clunky to use. Can you explain why?

top 50 comments
sorted by: hot top controversial new old
[–] [email protected] 84 points 2 months ago (10 children)

Any language in which whitespace has syntactic value is intrinsically flawed.

Can't speak to your specific issues, but that's why yaml will always suck.

[–] [email protected] 25 points 2 months ago (7 children)

As a serialization format, agree 100%, but would Python really be better if it switched to braces?

[–] [email protected] 63 points 2 months ago (8 children)

Yes, I think so. The downside with Python comes when refactoring the code. There’s always this double checking if the code is correctly indented after the refactor. Sometimes small mistakes creep in.

It’s really hard to tell when Python code is incorrectly indented. It’s often still valid Python code, but you can’t tell if it’s wrong unless you know the intention of the code.

In order languages it’s always obvious when code is incorrectly indented. There’s no ambiguity.

[–] [email protected] 12 points 2 months ago

I think this is just familiarity. I never have issues with indentation, but when refactoring js I'm always like hey who's fucking brace is this

load more comments (7 replies)
[–] [email protected] 29 points 2 months ago (3 children)

Yes it would - look at optional braces for short if expressions in C family languages and why it's so discouraged in large projects. Terminating characters are absolutely worth the cost of an extra LoC

[–] [email protected] 17 points 2 months ago (1 children)

I started in C before moving on to C++, Java, Ruby and Python.

I’ve had more bugs from missing braces than from misaligned whitespace because the latter is far more obvious when looking at a block of code.

[–] [email protected] 18 points 2 months ago (5 children)

Compilation error or run time errors? One is a gift and the other is a curse.

load more comments (5 replies)
[–] [email protected] 8 points 2 months ago* (last edited 2 months ago) (4 children)

False dichotomy. Optional braces are bad practice because they mislead the programmer that is adding an additional clause to the block.

This misleading behavior wouldn't happen in Python, as it would either be invalid syntax, or it would be part of the block.

Indentation problems are pretty obvious to the reader. Even more than missing or unbalanced braces.

[–] [email protected] 12 points 2 months ago (1 children)

They may be obvious to the reader but they may be impossible to see if tabs and spaces are mixed together.

Closing tokens are always clearer.

load more comments (1 replies)
load more comments (3 replies)
load more comments (1 replies)
[–] MajorHavoc 16 points 2 months ago* (last edited 2 months ago)

would Python really be better if it switched to braces?

Yes. A thousand times, yes.

load more comments (4 replies)
load more comments (9 replies)
[–] [email protected] 63 points 2 months ago* (last edited 2 months ago) (4 children)

Can people stop hating on shit?

FOR FUCKS SAKE, negative reinforcement dopamine has RUINED THE FUCKING NET.

EVERYWHERE I GO there's someone bitching about something, hate circlejerks are unbelievably popular, people just love to hate on stuff.

You're ruining your thought patterns with all these social media negativity bullshit.

Fucking TOML users hate on fucking YAML fucking C++ users hate Rust fucking Rust users hate literally everything under the sun and are insufferable to work with

EVERYONE, fucking CHILL

[–] [email protected] 47 points 2 months ago* (last edited 2 months ago)

Can you stop hating on haters? Thanks 😄

[–] sip 27 points 2 months ago

stop hating on rust devs

[–] beaumains 11 points 2 months ago (3 children)

Yeah TBH I like yaml. Sure its not the best ever, but its not the worst it could possibly be.

For config its not terrible. For ansible playbooks its again... not terrible.

Why is everyone always hating on something which is just kinda mid.

[–] [email protected] 8 points 2 months ago (3 children)

Config is fine, but Yamls biggest problem is people use it to describe programs. For example: playbooks. For example: CI steps.

If YAML wasn't abused in this way it would have a lot less hate.

load more comments (3 replies)
load more comments (2 replies)
load more comments (1 replies)
[–] [email protected] 43 points 2 months ago* (last edited 2 months ago) (8 children)

Programmers hate everything. You could design a spec which serenades you with angel song and feeds you chocolate dipped grapes and someone would be like: This is awful, my usecase is being a dog.

load more comments (8 replies)
[–] [email protected] 41 points 2 months ago (3 children)
[–] MajorHavoc 17 points 2 months ago

That is amazing.

I don't know what I just read.

If my website ever gets married, I'm going to invite this website to stand next to it as a bridesmaid - because it makes my website look pretty by comparison.

load more comments (2 replies)
[–] [email protected] 35 points 2 months ago (2 children)

Because people over use it. YAML is pretty good for short config files that need to be human readable but it falls apart with complex multi line strings and escaping.

I think there are much better clearly delimited for machine reading purposes formats out there that you should prefer if you're writing a really heavy config file and, tbh, I think for everything else .ini is probably "good enough".

[–] [email protected] 28 points 2 months ago (1 children)

At least use TOML if you like ini, there is no ini spec but TOML can look quite similar.

[–] [email protected] 10 points 2 months ago

Strong agree. It's also the absolute best at expressing really long documents of configuration/data.

[–] [email protected] 13 points 2 months ago* (last edited 2 months ago) (7 children)

I agree - YAML is not suitable for complex cases that people use it in, like ~~Terraform~~ and Home Assistant. My pet peeve is a YAML config in a situation that really calls for more abstraction, like functions and variables. I'd like to see more use of the class of configuration languages that support that stuff, like Dhall, Cue, and Nickel.

There is another gotcha which is that YAML has more room for ambiguity than, say, JSON. YAML has a lot of ways to say true and false, and it's implicit quoting is a bit complex. So some values that you expect to be strings might be interpreted as something els.

load more comments (7 replies)
[–] [email protected] 31 points 2 months ago

Following along with the style of your own post: YAML doesn't suck, because I feel so.

Thanks for asking.

[–] [email protected] 26 points 2 months ago (2 children)

I don’t like YAML because it’s overly complicated. The specification is like 80 pages long. How the hell did they think that was a good idea?

JSON on the other hand is super simple. It doesn’t do more than it needs to.

Just compare this: https://yaml.org/spec/1.2.2/

With this: https://www.json.org/json-en.html

The entire JSON specification is shorter than just the table of contents of the YAML specification!

Another thing I like about JSON is that you can format it however you want with the whitespace. Want everything on one line? Just write everything on one line!

If data can be represented as a JSON, then there’s generally only one way to represent it in JSON (apart from whitespace). In YAML the same data can be represented in 1000s of different ways. You pick one.

[–] [email protected] 26 points 2 months ago (1 children)

I will never forgive JSON for not allowing commas after the last element in a list.

load more comments (1 replies)
[–] verstra 13 points 2 months ago

This is the major reason for me. I really liked yaml, because it is way more readable to me than JSON. But then I kept finding new and more confusing yaml features and have realized how over-engineered it is.

Yaml would be great language if it had its features prunned heavy.

[–] [email protected] 26 points 2 months ago* (last edited 2 months ago)

One pattern I've noticed is people seeking a language that's better than {JSON,XML,INI,etc} at wrangling their slightly complex configuration files, noticing the additional features and type support offered by YAML, and assuming it will be a good solution.

Then, as their configs grow ever larger and more complex, they discover that expressing them in YAML requires large sections of deep nesting, long item sequences, and line wrapping. The syntax style that they saw working well in other places (e.g. certain programming languages) breaks down quickly at that level of complexity, making it difficult for humans to correctly write and follow, and leading to frequent errors.

YAML doesn't suck for small stuff, IMHO. (But it is more complex than necessary for small stuff.)

For things likely to grow to medium-large size or complexity, I would recommend either breaking up the data into separate files, or looking for a different config/serialization language.

[–] [email protected] 20 points 2 months ago (2 children)

To paraphrase: There are two kinds of markup languages. Those that people complain about and those that nobody uses.

There is no silver bullet that will work perfectly for all use cases and we also don't want to use 100 different tools. So people use things that aren't perfect. But they're good enough. I don't think YAML is perfect and I still use it, because people know it and there are tons of tools already available.

load more comments (2 replies)
[–] [email protected] 19 points 2 months ago* (last edited 2 months ago)

Tons of people making Python comparisons regarding indentation here. I disagree. If you make an indentation error in Python, you will usually notice it right away. On the one hand because the logic is off or you're referencing stuff that's not in scope, on the other because if you are a sane person, you use a formatter and a linter when writing code.

The places you can make these error are also very limited. At most at the very beginning and very end of a block. I can remember a single indentation error I only caught during debugging and that's it. 99% of the time your linter will catch them.

YAML is much worse in that regard, because you are not programming, you are structuring data. There is a high chance nothing will immediately go wrong. Items have default values, high-level languages might hide mistakes, badly trained programmers might be quick to cast stuff and don't question it, and most of the time tools can't help you either, because they cannot know you meant to create a different structure.

That said, while I much prefer TOML for being significantly simpler, I can't say YAML doesn't get the job done. It's also very readable as long as you don't go crazy with nesting. What's annoying about it is the amount of very subtle mistakes it allows you to make. I get super anxious when writing YAML.

[–] [email protected] 19 points 2 months ago

YAML works great for small config files, or situations where your configuration is fully declarative. Go look at the Kubernetes API with its resources.

People think YAML sucks because everyone loves creating spaghetti config/templates with it.

One reason it tends to become an absolute unholy mess is because people work around the declarative nature of those APIs by shoving imperative code into it. Think complicated Helm charts with little snippets of logic and code all over the place. It just isn't really made for doing that.

It also forces your brain to switch back and forth between the two different paradigms. It doesn't just become hard to read, it becomes hard to reason about.

[–] [email protected] 18 points 2 months ago (1 children)

I think TOML should replace YAML for config files, it is much clearer, easier to parse for a human.

load more comments (1 replies)
[–] [email protected] 18 points 2 months ago

I don't like a thing, fellas. With that being all I've told you, please explain why I don't like that thing.

[–] [email protected] 16 points 2 months ago (1 children)

It sucks the same way Python sucks. Some people just really don't like indentation-based syntax. I'm one of them, so I dislike both formats. However, if you groove on that sort of thing, I don't think YAML is any worse than any other markup.

Oddly, I get along with Haskell, which also used indentation for scoping/delimiting; I can't explain that, except that, somehow, indentation-based syntax seems to fit better with functional languages. But I have no clear argument about why; it's just an oddity in my aesthetics.

[–] [email protected] 11 points 2 months ago* (last edited 2 months ago) (9 children)

You can't say python's whitespace usage is as bad as yaml's. YAML mixes 2 and 4 spaces all the time. Python scripts don't run if you write this kind of crap.

And whitespaces is really just the tip of the iceberg of YAML problems...

load more comments (9 replies)
[–] [email protected] 16 points 2 months ago (1 children)

I didn't use yaml much while it was gaining popularity, and therefore didn't pay much attention. But this article really made me pay attention and now I distrust anything that uses yaml in any capacity.

https://ruudvanasseldonk.com/2023/01/11/the-yaml-document-from-hell

load more comments (1 replies)
[–] ITGuyLevi 13 points 2 months ago (1 children)

I hated yaml with every fiber of my being when first had to use it, but I really wanted to use HomeAssistant and see what I could do with it. I hated it a bit less when I started using docker compose. I started loving it when I started using it as a way to explain json to non-programming IT types, trying to explain it without braces and brackets seems to get across easier. I guess its more human readable, but as a result formatting has to be spot on (those indents and spaces replace the need for brackets and braces).

One useful trick if you truly hate it but need it, write it in json, then just use a converter to change that into yaml.

load more comments (1 replies)
[–] [email protected] 13 points 2 months ago (2 children)

I like yml. Clean to read, easy to use, supports comments.

load more comments (2 replies)
[–] [email protected] 13 points 2 months ago

But.. Yaml ain't markup language..

[–] [email protected] 12 points 2 months ago

YAML had comments and trailing commas, therefore it's objectively better than JSON. If you want a compromise solution that mostly looks like JSON, try JSON5.

[–] [email protected] 12 points 2 months ago (1 children)

it does what it needs to do: i don't think it's necessarily bad.

it's for data not programming and it handles complex structures cleaner than json

[–] [email protected] 8 points 2 months ago

My issue with it arises when data is not interpreted as I expected, like because of weird white space issues for example.

[–] [email protected] 11 points 2 months ago (1 children)

I don't hate YAML, but it has the same issues languages like PHP and JS introduce...there are unexpected corner cases that only exist because the designer wanted the language to be "friendly"

https://www.bram.us/2022/01/11/yaml-the-norway-problem/

load more comments (1 replies)
[–] [email protected] 11 points 1 month ago* (last edited 1 month ago)

I used to think json was the best until I found json lines or line delimited json. Thank me later. I use it all the time. You can append until you’re blue in the face. It’s great for log files. Each line is a valid json file.

load more comments
view more: next ›