this post was submitted on 06 Sep 2024
52 points (100.0% liked)

Programming

423 readers
1 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 !webdev@programming.dev



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

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
[–] Vivendi@lemmy.zip 47 points 2 months ago* (last edited 2 months ago) (3 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

[–] sip@programming.dev 21 points 2 months ago

stop hating on rust devs

[–] beaumains@programming.dev 7 points 2 months ago (1 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.

[–] wewbull@feddit.uk 4 points 2 months ago (1 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.

[–] derpgon@programming.dev 2 points 2 months ago (1 children)

What's wrong with using YAML for CI? I mean, I use it for Gitlab CI, the underlying script it runs is just Bash.

[–] wewbull@feddit.uk 3 points 2 months ago

Right, so you just have a single step and then hand over to a proper script. I've seen many people try to put much more complex logic in there before handing over to a proper language.

[–] orcrist@lemm.ee 5 points 2 months ago

No seeds no stems no stress my guy. The Internet is a great place for complaining. Readers can downvote and move on, everyone gets what they want.

[–] NaevaTheRat@vegantheoryclub.org 36 points 2 months ago* (last edited 2 months ago) (2 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.

[–] silverblade@discuss.tchncs.de 7 points 2 months ago (1 children)

This comment is underrated, even if it rises to the top of all comments.

[–] NaevaTheRat@vegantheoryclub.org 4 points 2 months ago

Pleased to have touched your life with levity, stranger.

[–] FizzyOrange@programming.dev 6 points 2 months ago (1 children)

Sure there aren't many things that are universally loved. I mean I can't really think of anything that doesn't have some flaw.

But that doesn't mean everything is equal! What would you rather program with, Visual Basic or Go? PHP or Typescript? If you polled people there are obvious winners.

[–] NaevaTheRat@vegantheoryclub.org 3 points 2 months ago (1 children)

Hey would you rather build from wood or steel?

What glue is better: 2 part epoxy or PVA?

Do you prefer soap or bleach as cleaning agent?

[–] FizzyOrange@programming.dev 3 points 2 months ago (1 children)

Would you rather build from wood or tissue paper?

What glue is better: 2 part epoxy or pritt stick?

Do you prefer soap or ash as a cleaning agent?

[–] NaevaTheRat@vegantheoryclub.org 2 points 2 months ago (1 children)

Unlike tissue paper yaml is actually fit for purpose. I actually don't know of any lang that literally can't run a program. The most you could stretch what you're saying to is that some esolangs are akin to making bricks of packed tissues to build with. They are art projects not serious submissions though.

I don't like js as much as anyone else but as evidenced by reality it works. Programmers need to stop sniffing their own farts, you have such strong opinions about the most insane shit when at most you should be talking about narrower scopes for use and trade offs.

load more comments (1 replies)
[–] gencha@lemm.ee 21 points 2 months ago

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

Thanks for asking.

[–] mox@lemmy.sdf.org 20 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.

[–] magic_lobster_party@fedia.io 19 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.

[–] lemmyng@lemmy.ca 18 points 2 months ago (1 children)

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

[–] NostraDavid@programming.dev 2 points 2 months ago

That lack of trailing comma has been the bane of my existence.

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

[–] state_electrician@discuss.tchncs.de 18 points 2 months ago (1 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.

[–] hex@programming.dev 1 points 2 months ago (1 children)

But it's not a markup language.. It's for data serialisation..

I remember the time when YAML meant Yet Another Markup Language.

[–] sxan@midwest.social 14 points 2 months ago

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.

[–] hades@lemm.ee 13 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

[–] biscuitswalrus@aussie.zone 5 points 2 months ago

Great link.

[–] LyD@lemmy.ca 12 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.

[–] demesisx@infosec.pub 10 points 2 months ago* (last edited 2 months 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.

[–] key@lemmy.keychat.org 9 points 2 months ago (2 children)

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

[–] GammaGames 5 points 2 months ago

Way easier to type than json!

[–] NostraDavid@programming.dev 1 points 2 months ago

and no possibility of (a lack of) trailing comma's. Unless you use JSON inside Yaml, you heathens!

[–] roadrunner_ex@lemmy.ca 8 points 2 months ago

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/

[–] cupcakezealot@lemmy.blahaj.zone 8 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

[–] matcha_addict@lemy.lol 5 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.

[–] GTG3000@programming.dev 7 points 2 months ago

It's inconsistent and annoying. Expressive, yes. Gets it's job done, yes. Absolute nightmare of a spec, YES.

The fact that JSON is a subset of YAML should tell you everything about how bloated the spec is. And of course there's the "no" funny things.

Personally, my favourite way to write configs was using lua (because it was already part of the project so why not), but JSON does fine.

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

[–] derpgon@programming.dev 6 points 2 months ago* (last edited 2 months ago)

Fun fact, since YAML is a superset of JSON, any JSON is a valid YAML. You can still use pure JSON.

[–] corsicanguppy@lemmy.ca 6 points 2 months ago

We all know it sucks. I have no idea why people use it instead of anything else. My workday is jammed with fucking ansible which, while also being so ghetto that we were easily doing more with less in 2002, uses So.much.fucking.yaml . Just when you think ansible couldn't get more clunky and useless and slow, it also is configured in yaml.

[–] thingsiplay 6 points 2 months ago

I don't like it either, but I'm not entirely sure why. Maybe the biggest flaw to me is it uses Python style indentation for structuring as part of data logic. It doesn't feel like a configuration language to me and it does not feel simple too. It's also unlike most programming language structures (maybe besides Python), so it looks weird to read and write. Other than that, I don't know exactly why I don't like this format much. Admittedly, I did not do much in YAML, so because lack of experience take my opinion with a thick grain of salt.

We have JSON and TOML. I quiet like TOML. We have "better" alternatives, that are probably easier to parse. And therefore there is not much need for YAML. Maybe if YAML was the default config format for Python it would get off the ground and be accepted more often.

[–] lolcatnip@reddthat.com 5 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.

[–] ulkesh 5 points 2 months ago

White space/indentation as a construct of the syntax.

It’s why I have a hard time with python.

People have their likes and dislikes. Nothing wrong with that.

[–] MajorHavoc@programming.dev 5 points 2 months ago

If YAML and JSON were gripping my hands for dear life, dangling off of a cliff...

I would let both drop into the abyss so I could spend more time with INI.

[–] Damage@feddit.it 5 points 2 months ago

I think much of the issue with YAML is that it's often paired with bad editors. You need a way to manage the whitespace, collapse sections, etc. Notepad doesn't cut it.

[–] cosmicbytes@programming.dev 2 points 2 months ago (1 children)

I wish s-expression was a popular alternative. It's readable without the yaml issues.

[–] NostraDavid@programming.dev 2 points 2 months ago* (last edited 2 months ago) (1 children)

YAML is fine if you use a subset (don't use the advanced features - not like you know those anyway) and use explicit strings (always add " to strings), otherwise things may be cast when you did not intend values to be cast.

Example:

country: NO (Norway) will be cast to country: False, because it'll cast no (regardless from casing) to false, and yes to true.

country: "NO" should not be cast.

[–] NostraDavid@programming.dev 1 points 2 months ago* (last edited 2 months ago) (1 children)

People are working on making S-Expressions a standard: https://datatracker.ietf.org/doc/draft-rivest-sexp/

Note: This is just a draft, but improvements have been happening since 2023.

I probably won't like the parentheses, but I think I'll take it over yaml/json/whateverelse.

[–] FizzyOrange@programming.dev 5 points 2 months ago (2 children)

That appears to not support comments. How they made that mistake after JSON is a mystery.

load more comments (2 replies)
[–] Eryn6844 2 points 2 months ago

cradles yaml in her hands and coos don't you talk to my baby like that! she has potential !

load more comments
view more: next ›