Carl Johnson changelog.com/posts

XML is better than YAML. Hear me out...

there's always something better than YAML

This is a fancified excerpt of Carl M. Johnson’s unpopular opinion on the Go Time podcast. Click here to listen along while you read or watch the video on YouTube. Jump to the end for the poll results. 📊


My spicy take is that XML is better than YAML, because there are situations where XML is appropriate, but there’s no situation where YAML is appropriate.

Johnny Boursiquot: Dang. Shots fired! 🤣

Let’s talk about XML first

So, XML got a really bad reputation. The reason it got a really bad reputation is because people were using it for things that it should never have been used for. XML stands for Extensible Markup Language. And if you’re using it as an extensible markup language, it’s actually really great.

Let’s say you’re working on something and you’re like:

“I’m making a new kind of book, and I need to annotate all of the verses in the Bible, and have the chapter headings and stuff.”

It’s great for that.

It’s really good for when you have a document, and some things are italicized, and some things are in a foreign language, and subtitles, and all that stuff. It’s really good for that. It’s not good if it’s like:

“I need to configure this server and the server needs to know if this value is true or false.”

No, that’s bad. Don’t do that. That’s not a good use for XML.

But XML does have some uses for which it’s appropriate. And I think the fact that now everybody is writing React… and they’re writing it with JSX… and JSX is basically just inline XML… I think that shows that there are cases where actually XML is pretty good.

YAML on the other hand

YAML on the other hand I think is never good. There’s always something better than YAML!

We’ve finally made it to Go 1.21 and I’m very happy about this. And you know why? Because YAML repeatedly bit me in the behind on Go 1.20. Ask me why.

Johnny Boursiquot: Why?

Well, when you say in your test file:

“test this against Go 1.20”

It interprets that as Go 1.2. 😭🤣

So it was like two or three different times I had a repo where I’m like:

“These tests aren’t passing. Why are my tests not passing?! I’ve just upgraded to Go 1.20.”

And it was like:

“Oh, no. I’ve decided that this is Go 1.2”

And so YAML is always going to do that to you…

Better choices

Now, I understand why people do YAML, but there are better choices. You can use TOML. You can use CUE. You can use lots of things.

I like how Caddy does it. With Caddy, the canonical language that Caddy understands is JSON, but they have adapters.

So if you want to write YAML, you can. But it’ll just take that YAML and turn it into JSON behind the scenes. Then they also have a specific Caddy language. So you can give it the Caddy language and then it turns that into JSON behind the scenes. And you can give it an NGINX config and it’ll turn that into JSON behind the scenes. If you have the cycles and time to spare, that’s probably the best solution for most people…

But when the only way to do it is YAML, it’s like:

“No…!”

It’s just too error-prone, there’s too many things… You just have to always quote everything.

Also…

Also the YAML specification has all these features that nobody ever uses, because they’re really confusing, and hard, and you can include documents inside of other documents, with references and stuff… And it’s like

“Oh, man, I don’t want to have to understand any of this stuff.”

And then if you’re not careful, it’d be like:

“Oh yeah, the first three things I fed it to understood that, but then the third one was just like using some parser that they found on the back of a truck, and it doesn’t understand it”

and it’s like:

“Oh, man…”

YAML… never appropriate. XML is sometimes appropriate.


The polls are closed 🗳️

There you have it. Carl’s reasoning for why XML is better than YAML. Do you agree or disagree? The poll results are in on Mastodon and X!

But you can still duke it out in the comments below … we’re listening! 👇


Discussion

Sign in or Join to comment or subscribe

2023-09-20T18:26:15Z ago

This is so true! YAML always feels so icky to me, like Ruby and Ruby on Rails do, too. Just like Ruby and RoR, YAML is too opinionated, and its opinions are almost always wrong! Give me JSON or give me XML, please.

Davide Mauri

Davide Mauri

Redmond, Washington

I started as a developer, I fell in love with Data and Database, in all their forms. I still have a passion for development (C# and Python). My focus has been databases and performance tuning, focusing both on transactional and analytical workloads. For 5 years I helped developers to get the best out of SQL Server, then I moved to Business Intelligence and Data Warehousing for 10 years. Then I moved to IoT and Big Data for a while. Now back to database space, as Product Manager for Azure SQL Database, helping developers to re-discover SQL, using any platform and any OS.

2023-10-03T15:05:56Z ago

YAML is almost impossible to use when the data structure is non-trivial and when data start to be a bit more than a few lines of text. Hard to read, hard to write, I’m definitely not a fan of it. JSON is definitely better. Or ToML.

Player art
  0:00 / 0:00