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…
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:
It’s just too error-prone, there’s too many things… You just have to always quote everything.
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:
YAML… never appropriate. XML is sometimes appropriate.
The polls are closed 🗳️
But you can still duke it out in the comments below … we’re listening! 👇