Live data from Hacker News

YAML: Probably not so great after all

arp242.net

351–360 of 457 posts

Re: YAML: Probably not so great after all

#351
post #298

Earlier quoted context omitted.

When maintaining a JSON file, did you ever happen to wonder why a particular value is what it is? This is where comments belong.

If it's that important and complex, have an accompanying README that lists line numbers and comments.

Good idea! And then put a comment into the configuration file that refers to where the documentation is.. ah, f__k!

Re: YAML: Probably not so great after all

#352
post #146
post #100

Earlier quoted context omitted.

How about JSONL (JSON Lines)? http://jsonlines.org/ Ps. Thanks for (all the) fish, it's my daily driver shell and keeps me that much more sane c.f. the alternatives.

That's really close to [RFC 7464]( https://tools.ietf.org/html/rfc7464 ), JSON Text Sequences. It uses U+001E RECORD SEPARATOR. The `jq` tool supports those if you pass a flag.

jq can also handle newline-separated JSON objects, with the -s flag.

Re: YAML: Probably not so great after all

#353
post #78

Earlier quoted context omitted.

Other than looking ugly and being a pain to type does xml actually suck?

Is there an agreement on whether it’s or pete yet?

Yes there is. Markup languages are for representing rich text. Anything that gets rendered to the user is content and anything that's metadata (data about how to render) but not rendered as such goes into attributes. If there is no concept of "rendering to the user" in your app/data, then markup isn't the right choice for representing your data. You're blaming markup languages for not being designed to represent arbitrary data structures when you should be blaming yourself for misusing and misunderstanding markup. Though by skimming through this thread, XML appears to still do much better than YAML. And it's true that in the 00's, XML was improperly used and advocated as universal data format.

Re: YAML: Probably not so great after all

#355

There's two types of formats: 1) those people complain about, and 2) those no one use.

TOML seems widely used but I've never seen complaints about it. I'm sure there are some, but the only time I see it mentioned is when someone is recommending someone else switch to TOML.

Out of curiosity, is there anyone here who doesn't like TOML for configuration?

Re: YAML: Probably not so great after all

#356
post #296

Earlier quoted context omitted.

ini if needs are crazy simple, YAML if you need a structure like JSON's but with something any human ever needs to interact with. JSON if humans aren't in the loop. TOML, in my opinion, is like a weird mishmash of JSON, ini, and bashisms. Though I have worked with it a lot less than the other formats, so YMMV.

Since when is JSON not human readable/maintainable??

Try writing strings with backslashes, or adding a new line to your array and accidentally leaving a trailing comma (or accidentally forgetting it for the previous row). It's also just very visually noisy. I agree with a lot of the other comments in this thread that for human configuration: TOML > YAML > JSON > XML

Re: YAML: Probably not so great after all

#357
I've recently started using https://jsonnet.org/ to generate more complex config.

It's easier to write than JSON (no need to quote keys, allows trailing commas), has reusability through functions and objects, and can output JSON which is much easier to parse than YAML.

Downside: you need another build step for the config.

Re: YAML: Probably not so great after all

#358

From my experience, while YAML itself is something one can learn to live with, the true horror starts when people start using text template engines to generate YAML. Like it's done in Helm charts, for example, https://github.com/helm/charts/blob/master/stable/grafana/te... Aren't these "indent" filters beautiful?

I developed Yet Another JSON Templating Language, whose main virtue was that it was extremely simple to use and implement, and it could be easily implemented in JavaScript or any other languages supporting JSON.

We had joy, we had fun, we had seasons in the sun, but as I added more and more features and syntax to cover specific requirements and uncommon edge cases, I realized I was on an inevitable death-march towards my cute little program becoming sufficiently complicated to trigger Greenspun's tenth rule.

https://en.wikipedia.org/wiki/Greenspun%27s_tenth_rule

There is no need for Yet Another JSON Templating Language, because JavaScript is the ultimate JSON templating language. Why, it even supports comments and trailing commas!

Just use the real thing to generate JSON, instead of trying to build yet another ad-hoc, informally-specified, bug-ridden, slow implementation of half of JavaScript.

Re: YAML: Probably not so great after all

#359

Earlier quoted context omitted.

Giving meaning to whitespace causes so many headaches and yet people still embrace Python, for some reason. I don’t understand it.

Your editor makes a world of difference here. Since you shouldn't be writing brace-language code without indents anyways, the biggest issue remaining is mixing tabs and spaces. Gedit makes this a big pain with it's default config (it doesn't even auto-indent) but Atom and IDLE handle it well.

If I pinky promise to indent my code anyway, then why does it matter whether I also have braces or not? In fact, braces allow me to press one button in my editor and get the indentation absolutely perfect, without affecting semantics.

Braces also allow for easily copying and pasting blocks of code because the braces delimit the semantics of the copied text. Because your code is already indented, with white space indentation you have to check that a) you pasted the first line at the right indentation level b) every subsequent line is also at the right level relative to the first line. No small feat.

Re: YAML: Probably not so great after all

#360

So what's the HN consensus on the best format for config files? Is it TOML as the author seems to prefer at the end?

The main issue I had with TOML is how much more syntactically noisy it is. Equivalent files with 2-3 levels of nesting usually become at least 50% longer than equivalent YAML. More here : https://hitchdev.com/strictyaml/why-not/toml/

This is a different use case, I think. This example is defining content, not configuration. In this case the content is user stories. I agree for creating sequences of documents/content in this way, YAML often is nicer. But for configuration, TOML is designed to specify it in a simple and flat way, and that can be very helpful.

I have some projects where I'm frequently writing and midifying content that resembles the example here, and I use YAML there and plan to keep using YAML. For most other things, I'm just doing configuration, so I use TOML. No reason you need to stick to one or the other.

Post reply on HN