News for hackers. Stuff that matters.
Re:Bugs in the YAML specification by ThePhysicist on Sunday September 04, 2016 @03:24PM (#12426218)
What I find more interesting is that YAML allows you to define self-referential / circular data structures:

    foo: &foo
      bar: *foo
In PyYAML, this will give you a self-referntial dictionary. Powerful but pretty catastrophic if you use (naive) recursion to analyze a user-submitted data structure.
Re:Bugs in the YAML specification by twelvechairs on Sunday September 04, 2016 @04:33PM (#12426562)
Feature not a bug. YAML is what people turn to who need these kind of advanced feautures which arent provided in json or similar.
Re:Bugs in the YAML specification by OskarS on Sunday September 04, 2016 @04:38PM (#12426592)
I would imagine this feature is primarily useful if you want to serialize a whole bunch of objects that all reference each other, but it makes me feel a bit icky. It feels like it breaks an intuitive assumption you have about hierarchical formats, which is that there should be no cycles.

Maybe that's just my personal bias, but I feel like the relative simplicity of JSON is a strong feature in its favor. As a developer, I have very clear understanding of the data I'm reading, and with that I can more easily make safer and more stable code.

Re:Bugs in the YAML specification by junke on Sunday September 04, 2016 @04:43PM (#12426618)
Yet, a lot of hierarchical structures I see are full of "ref" and "id" attributes, which effectively encode cyclic graphs.
Re:Bugs in the YAML specification by OskarS on Monday September 05, 2016 @05:42AM (#12429162)
That's certainly true, but at least that's not going to cause an infinite loop while wandering down the structure, it's just gonna end at a leaf "ref" or "id".
Re:Bugs in the YAML specification by junke on Monday September 05, 2016 @07:49AM (#12429618)
In my view this is more a question of simple interface vs. simple implementation. Having cross-references at the language level gives a uniform and simplified interface at the cost of more having to develop careful tools.

Not saying refs/id are bad, but at least with a uniform syntax and language support, you don't have to reimplement custom cross-reference resolvers.

Re:Bugs in the YAML specification by twelvechairs on Sunday September 04, 2016 @05:34PM (#12426836)
You are right for most use cases - which is why json is so popular. Sometimes however there is very good reason to have non-hierarchical data - and YAML fits this use case.
Re:Bugs in the YAML specification by crdoconnor on Sunday September 04, 2016 @06:03PM (#12426936)
>YAML is what people turn to who need these kind of advanced feautures

Most people don't use these features.

Re:Bugs in the YAML specification by Sir_Substance on Sunday September 04, 2016 @06:05PM (#12426944)
But twelvechairs' contention is that the people who do need them turn to YAML :)
Re:Bugs in the YAML specification by crdoconnor on Sunday September 04, 2016 @06:37PM (#12427057)
Except the people who use YAML don't seem to use them:

https://github.com/search?o=desc&p=2&q=data+language%3AYAML&...

Re:Bugs in the YAML specification by kelseyfrancis on Sunday September 04, 2016 @08:40PM (#12427467)
I'm not sure what your search query is supposed to prove. That something is rare doesn't mean it doesn't exist. I have personally used this YAML feature, albeit very rarely, obviously.
Re:Bugs in the YAML specification by timv on Sunday September 04, 2016 @09:23PM (#12427574)
His query is attempting to show that while

> YAML is what people turn to who need these kind of advanced feautures

might be literally true, it is also true that

YAML is what many people turn to even if they don't use those features

So the original concern of

> Powerful but pretty catastrophic if you use (naive) recursion to analyze a user-submitted data structure.

is probably reasonable.

There is a pretty good likelihood that many YAML users (i.e. the app developers) are unaware of the power exposed in the format, and the possible consequences of parsing & walking user input.

It brings back all sorts of memories of XML entity attacks, etc. When developers build simple data interchange methods on top of complex formats that they don't fully understand, all sorts of issues emerge.

It's not YAML's problem per se - it's very helpful that there is a commonly used, complex data format for people who need such features. It would be far worse if everyone was inventing their own solution for this - but the reality on the ground is still pretty messy.

Re:Bugs in the YAML specification by crdoconnor on Monday September 05, 2016 @06:46AM (#12429389)
>It would be far worse if everyone was inventing their own solution for this

They are - HJSON, JSON5, TOML, etc. Most of these reference YAML's overcomplicated spec as a reason for their existence.

Re:Bugs in the YAML specification by cm3 on Sunday September 04, 2016 @07:22PM (#12427206)
It's how config is shared in, say, .gitlab-ci.yml or .travis.yml. So, it is used and a widely documented use case at that. Not recursively, of course.
Re:Bugs in the YAML specification by crdoconnor on Sunday September 04, 2016 @08:21PM (#12427395)
I've never seen a node anchor and reference used in .gitlab or .travis, let alone a recursive one. Just text, list & associative array.
Re:Bugs in the YAML specification by jdmarble on Sunday September 04, 2016 @10:30PM (#12427772)
The most popular repository on GitLab.com uses these features extensively: https://gitlab.com/gitlab-org/gitlab-ce/blob/master/.gitlab-...
Re:Bugs in the YAML specification by crdoconnor on Monday September 05, 2016 @05:20AM (#12429087)
Fair enough.

It does seem to be a rarely used feature though. Furthermore it confuses non-programmers who otherwise are happy with YAML (I've tested this, it really does).

Given all of this, and given that what it does can be easily achieved in other ways that don't require the feature, I think it's a net negative overall to have it in the spec.

Re:Bugs in the YAML specification by cm3 on Monday September 05, 2016 @05:29AM (#12429116)
I may be rarely used, generally speaking, but it's used a lot in CI configs. The linked example is the typical use case, and it's documented in both CI services' config section.

I'm certain this feature is a major reason why YAML was chosen for CI config over TOML or JSON, and the way it's used in those config files is, as I said, _not_ recursive, so the issue discussed here isn't relevant. Rejecting recursive definitions can be a sensible improvement.

What other ways do you have in mind that would be a viable replacement?

Re:Bugs in the YAML specification by crdoconnor on Monday September 05, 2016 @06:05AM (#12429241)
>What other ways do you have in mind that would be a viable replacement?

Where there is not very much repetition required, simply use repetition instead (e.g. in the above example I would just copy & paste use-db to the relevant locations). The increased readability makes it worth the repetition where there's not a lot of it.

Where there is a lot of repetition I'd consider that a bug or feature required in the schema and would refactor the YAML schema and the parsing code so that less repetition is necessary for most configs.

I don't consider the above CI config particularly easy to understand and even with the node anchors and references there's a bunch of repetition (e.g spinach 1, spinach 2, spinach 3, etc.). That's partly because of the node anchors and references. It would look better if they refactored the schema.

Re:Bugs in the YAML specification by cm3 on Monday September 05, 2016 @06:29AM (#12429313)
> repetition (e.g spinach 1, spinach 2, spinach 3, etc.)

Without a looping or sequence construct, this will be hard to avoid, and once you go that route, you might as well adopt a Lisp as your config syntax.

Before there was XML, there was SGML, and SGML has DSSSL, which was a Scheme dialect, and that was a brilliant idea which has been ditched for XML and its surrounding specs. S-Expressions are natural for the task. There are still prominent uses of S-Expressions, even in the OCaml world, where Jane Street uses it for configuration and serialization.

The full power of a Lisp may be too much and risky, but you can restrict the spec and allow only certain constructs, so that you can ensure it will evaluate to a result in a quick and deterministic way.

The little "templating" feature used in gitlab-ci.yml is a huge benefit, and as long as parsers limit the feature, it's a good compromise between complexity and comfort.

There is a lot of experience with using Lisp for configuration, and that experience can be leveraged to come up with a good S-Expressions based config format that's flexible, deterministic, and known to terminate in constant time. If you're careful with the spec, you could even validate the config fully.

Re:Bugs in the YAML specification by cm3 on Monday September 05, 2016 @06:39AM (#12429353)
So, I'm actually surprised no Lisp dialect has gained popularity in the modern web stacks for configuration. Maybe if Clojure were more popular and less XML-influenced from the JVM world. Just thinking out loud.
Re:Bugs in the YAML specification by techdragon on Sunday September 04, 2016 @07:41PM (#12427268)
In my experience, YAML is what people turn to when they want something like JSON, but don't want to have to type the extra braces and quotation marks.
Re:Bugs in the YAML specification by untog on Sunday September 04, 2016 @08:15PM (#12427377)
That's certainly my use case. Things like easy multi-line strings make it very useful, and readable by less tech-inclined folks. Though for that audience ArchieML is better still:

http://archieml.org

Re:Bugs in the YAML specification by ChoHag on Monday September 05, 2016 @06:45AM (#12429381)
If you're doing naive recursion, you're doing it wrong.