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

Programming

17351 readers
350 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
62
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?

you are viewing a single comment's thread
view the rest of the comments
[–] sxan@midwest.social 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.

[–] eager_eagle@lemmy.world 11 points 2 months ago* (last edited 2 months ago) (2 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...

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

YAML mixes 2 and 4 spaces

I think that's a user thing and it doesn't happen if you have a linter enforce 2 or 4.

[–] eager_eagle@lemmy.world 8 points 2 months ago* (last edited 2 months ago) (1 children)

That's part of the problem. Different number of whitespaces indicate different nesting levels and the YAML spec does not enforce them. These two horrible YAMLs are valid and are not equivalent:

a:
 b:
     - c
     -  d
      - e
f:
    "ghi"
a:
 b:
     - c
     - d
     -  e
f:
    "ghi"
[–] zero_spelled_with_an_ecks@programming.dev 0 points 2 months ago (1 children)

So it's easy to enforce locally but you don't have to. And it's easy to see indentation on modern IDEs and you can even make your indents rainbows and collapse structures to make it easier to see what's going on, but I guess since some people want to write it in vi without ALE or a barebones text editor, it's bad? Like there are legit reasons it's bad, and other people have mentioned them throughout the thread, but this seems like a pretty easy thing to deal with. I work with ansible a bunch and YAML rarely is where my problem is.

[–] atzanteol@sh.itjust.works 6 points 2 months ago (1 children)

Jesus, just what I want to do with the devops team - spend a few weeks standardizing on an editor and configuring them to edit yaml.

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

A few weeks? How do you stay employed? How do you even feed yourself at that pace? Blocked on making a sandwich, I've got the wrong type of bread.

It's three lines in an editor config file to standardize the indents across any editor: https://editorconfig.org/

In vscode, adding two extensions is all I need:, yamllint (if you don't use linters, I don't know how you do your job in any language) and rainbow indents. Atom had similar ones. I'm sure all IDEs are capable of these things. If you work at a place that forces you to use a specific editor and limits the way you can use it, that's not YAML's fault.

At a certain point, it's your deficiencies that make a language difficult, not the language's. Don't blame your hammer when you haven't heated the iron.

[–] atzanteol@sh.itjust.works 0 points 2 months ago (1 children)

You know how many editor plugins I need to work with json? None.

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

You want an award? I hate working with JSON without a prettier.

[–] atzanteol@sh.itjust.works 2 points 2 months ago* (last edited 2 months ago) (1 children)

YAML mixes 2 and 4 spaces all the time. Python scripts don't run if you write this kind of crap.

Sure it does. You only need to be consistent within a block. Python's syntax is ridiculous and solves problems that basically don't exist.

All of my java/kotlin/rust/etc. code is trivially well formatted and can be done by my editor. Moving code blocks is trivial. Refactoring is easier when I didn't need to hand -format the code just to make it work.