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?

  • mox@lemmy.sdf.org
    link
    fedilink
    arrow-up
    0
    ·
    edit-2
    12 days 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, discovering 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.

  • lehenry@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    12 days ago

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

    • NostraDavid@programming.dev
      link
      fedilink
      arrow-up
      0
      ·
      11 days ago

      Depends on the data structure. If you want to save a table of sorts, you’re getting a bunch of unreadable [[[]]] nonsense.

      For flat structures it’s great though.

  • 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
      link
      fedilink
      English
      arrow-up
      0
      ·
      edit-2
      12 days ago

      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…

        • Eager Eagle@lemmy.world
          link
          fedilink
          English
          arrow-up
          0
          ·
          edit-2
          12 days ago

          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"
          
          • 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
              link
              fedilink
              English
              arrow-up
              0
              ·
              12 days ago

              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.

              • 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
        link
        fedilink
        English
        arrow-up
        0
        ·
        edit-2
        12 days ago

        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.

  • LyD@lemmy.ca
    link
    fedilink
    arrow-up
    0
    ·
    11 days 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.

  • ITGuyLevi@programming.dev
    link
    fedilink
    arrow-up
    0
    ·
    11 days ago

    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.

  • NostraDavid@programming.dev
    link
    fedilink
    arrow-up
    0
    ·
    edit-2
    11 days ago

    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.

        • palordrolap@fedia.io
          link
          fedilink
          arrow-up
          0
          ·
          11 days ago

          That’s a thorny question: Do comments need to be in the base standard, or can that be offloaded to those building on it? It doesn’t look like it would be hard to have (comment "foo bar baz") in an expression and have a re-parser throw that out.

          Is the complaint that no two groups of people will use the same comment standard if left to their own devices? It’s not like the other data from different sources will always match up. What’s one extra, and fairly easy to handle SNAFU?

          That said, yes, I think I’d be more comfortable knowing there was an accepted comment format. The aesthetic seems to be Lisp-like, and I notice that the Lisp comment marker, the semicolon, is currently a reserved character, that is, it’s illegal to use it unquoted. Maybe they’re thinking of adding that at some point.

          • FizzyOrange@programming.dev
            link
            fedilink
            arrow-up
            0
            ·
            11 days ago

            It doesn’t look like it would be hard to have (comment “foo bar baz”) in an expression

            That is pretty much what the official “solution” is for comments in package.json - add "//": "foo bar baz" keys to dictionaries and NPM will ignore them.

            In practice it’s terrible. You need real comments.

  • MajorHavoc@programming.dev
    link
    fedilink
    arrow-up
    0
    ·
    12 days 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.

  • magic_lobster_party@fedia.io
    link
    fedilink
    arrow-up
    0
    ·
    12 days ago

    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
      link
      fedilink
      English
      arrow-up
      0
      ·
      12 days ago

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

    • verstra@programming.dev
      link
      fedilink
      arrow-up
      0
      ·
      12 days 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.

  • katy ✨@lemmy.blahaj.zone
    link
    fedilink
    arrow-up
    0
    ·
    12 days ago

    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
      link
      fedilink
      English
      arrow-up
      0
      ·
      12 days ago

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

  • Damage@feddit.it
    link
    fedilink
    arrow-up
    0
    ·
    12 days 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.

  • GTG3000@programming.dev
    link
    fedilink
    arrow-up
    0
    ·
    11 days 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.

  • state_electrician@discuss.tchncs.de
    link
    fedilink
    arrow-up
    0
    ·
    11 days ago

    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.

  • UnfortunateShort@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    edit-2
    11 days 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.

  • Vivendi@lemmy.zip
    link
    fedilink
    arrow-up
    0
    ·
    edit-2
    11 days ago

    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

    • Sir Gareth@programming.dev
      link
      fedilink
      arrow-up
      0
      ·
      11 days ago

      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
        link
        fedilink
        English
        arrow-up
        0
        ·
        11 days ago

        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
          link
          fedilink
          arrow-up
          0
          ·
          11 days ago

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

          • cashew@lemmy.world
            link
            fedilink
            arrow-up
            0
            ·
            11 days ago

            You’re doing it right by avoiding as much of Gitlab’s CI features. I’ve seen versions where scripts are inlined in the YAML with expressions in random rule fields and pipeline variables thrown all over the place. And don’t get me started on their “includes” keyword, it’s awful in practice, gives me nightmares.

            Then I write a Kubernetes manifest in YAML with JSON schema validation and the heart rate goes down again.

          • wewbull@feddit.uk
            link
            fedilink
            English
            arrow-up
            0
            ·
            11 days 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.

      • SandLight@lemmy.world
        link
        fedilink
        English
        arrow-up
        0
        ·
        11 days ago

        I dream of a life where I use YAML but all my configs are stuck in XML. People can complain but there’s always worse options.

        • FizzyOrange@programming.dev
          link
          fedilink
          arrow-up
          0
          ·
          11 days ago

          One nice thing about XML is that there’s an official way to link to the schema from within the document. If you do that you can easily automatically validate it, and even better you get fantastic IDE support via Red Hat’s LSP server. Live validation, hover for keys, etc.

          It’s a really nice experience and JSON schema can’t really match it.

          That said, XML just has the wrong data model for 99% of use cases.

    • orcrist@lemm.ee
      link
      fedilink
      arrow-up
      0
      ·
      11 days 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.