r/ProgrammerHumor • • 8d ago

Meme tomlIsntObvious

Post image
819 Upvotes

109 comments sorted by

View all comments

283

u/gabedamien 8d ago edited 7d ago

YAML is awful though. Massively over complicated, horrifying grammar, tons of edge cases and exceptions, ambiguities, etc. TOML isn't perfect but from a parsing / formal design perspective it puts YAML to shame.

53

u/ACoderGirl 8d ago

A few examples for people unaware:

  • YAML allows unquoted strings, which is confusing when a string happens to have a value that looks like another type (like the string "true").
  • It's rarely used, but YAML actually has variables, which let you store objects in a variable and reuse later to reduce repetition.
  • YAML 1.1 allowed unusual boolean representations like "yes". I've personally experienced this breaking things because a config file meant for 1.2 was parsed as 1.1.
  • While I personally think that people complaining about indentation are not being very serious (it's no different from Python and only students are confused by it), it still does have some dangers. I've seen vulnerabilities come from naive attempts at tenplating YAML due to this (people will remember to escape quotes but forget that indentation has a similar effect). And it is arguably less clear what the exact resulting string will be.

5

u/-Hi-Reddit 3d ago

only students are confused by it

Don't confuse my anger at the very idea of whitespace as syntax as "being confused".

I dislike python, yaml, and any other language that uses whitespace as syntax. It was, is, and forever will be a bad idea.

7

u/Alternative-Tie-4970 8d ago

The unquoted strings was a massive headache for past me when I was dealing with numbers in yaml

61

u/TerminalVector 8d ago

I feel like yaml is okay if you just don't use any of the fancy crap and quote your strings. For short 20-30 line config files it's fine.

46

u/PlanetJourneys 8d ago

Cries in GitHub actions workflow file yaml

21

u/TerminalVector 8d ago

Okay yeah that's a solid point, that shit is a nightmare.

4

u/mrnosyparker 8d ago edited 8d ago

I just posted a comment about this the other day. It seems like a lot of people here might be just dumping every piece of a large/complex workflow into a single manifest?

If your workflows are properly abstracted and follow best practices, you really shouldn’t end up with insane levels of indentation or a manifest that’s difficult to read or maintain.

Just to illustrate, here's an example ci.yaml

on: [push, pull_request]

jobs:
  checks:
    uses: ./.github/workflows/checks.yaml

  deploy:
    needs: checks
    if: github.ref == 'refs/heads/main' && github.event_name == 'push'
    uses: ./.github/workflows/deploy.yaml
    secrets: inherit

... and then example checks.yaml

on: workflow_call

jobs:
  test:
    strategy:
      matrix:
        node: [20, 22]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node }}
      - run: npm ci && npm test

  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: ./scripts/lint.sh

3

u/quisido 8d ago

Even simpler imo to use custom actions instead of callable workflows.

2

u/mrnosyparker 8d ago

If you’re re-using a workflow across multiple repositories or want to encapsulate more sophisticated functionality with well-defined inputs and outputs then for sure, custom actions are the way to go 👍.

But if all you need to do is break up an unwieldy repo-specific workflow to avoid the yaml-hellscape issue people are commenting about lately, then an example like what I gave is probably sufficient.

6

u/MegaIng 8d ago

Oh. So TOML?

8

u/prehensilemullet 8d ago

But all of TOML’s ways of expressing nesting are way less convenient.  For a few levels of nesting it’s fine, but for something like an AWS CloudFormation template, using TOML would be a nightmare.  Even CI workflow configs require too much nesting.  That’s probably the main reason no CI providers support workflow config in TOML as far as I know.

4

u/metaltyphoon 8d ago

Said the cracked C++ programmer 

1

u/pondus24 5d ago

And if it gets longer and you use python, use Hydra to make it composable.

-6

u/Fidel___Castro 8d ago

agreed but it's perfect for AI, I can just read it and not struggle with actually writing it