102 points · by networked · 10y ago · 77 comments
Today I learned that what I perceived as somewhat complicated syntax is actually overwhelmingly complex.
I know that my preference for s-expressions is not shared by everyone, but the more complex a syntax I encounter, the more I wonder if simpler alternatives were even considered.
Genuine question: apart from inertia, and apart from recursive references (noted in comments before I wrote this), is there a use case for YAML that isn't solved by simpler and less ambiguous formats like EDN or Transit?
On the other hand I picked up YAML in less than a day (many years ago) and despite its complexity can't remember that ever causing me any issues. Not 100% sure if missing from your suggested formats (which do support multi line strings) but I enjoy use of yaml's folded strings.
The big problem is when the useless features that you should, never, ever use (and if you do you are doing it wrong) bite you on the arse. Because it tried to do too much, like XML, even when we knew that was a bad idea. But is is still the best 'JSON with better layout' out there, which is what we want when we want readable documents and maintainable code. EDN, Transit and TOML all fail in that somewhere, IMO, and of course popularity is actually a hugely important feature for any data interchange format.
IMO, a human writable format shouldn't need a help page like this: http://docs.aws.amazon.com/codedeploy/latest/userguide/app-s...
Yes, part of that is CodeDeploy, but saying "tab characters must not be used in indentation" for me, disqualifies a standard as "human writable".
CodeDeploy makes that horrendous by requiring five or so clicks to figure out what causes an error (try forgetting adding an app spec.yml file or saving a file with a BOM)
I've had more trouble with things trying to allow both spaces and tabs than I've had with YAML's refusal to allow tabs.
If you want a configuration format, ingy and I designed JSONY for that.
This was my attempt to cut out 90% of the crap, leaving the nice, readable core (which maps on to JSON pretty neatly):
In other words, people don't understand the need for it. Those that do use other formats - json or toml, namely.
Writing movie scripts in YAML using unquoted strings? That's pretty contrived. Using literal style is easy when it is potentially needed (e.g. programmatic output), and any decent editor can highlight inferred types in helpful ways. I've used YAML in a variety of contexts and never been bitten by this one, and I don't think that any of his examples are still problems in YAML 1.2 (from 2009).
The Ruby security problem they reference is also absurdly misattributed. The problem there is with trusting serialized data to mark its own types, and having no limits on what types can be deserialized into. That's a depressingly common security problem in many web frameworks, and YAML as an interchange format isn't a unique source of vulnerability. Any data format is dangerous on the web if you trust it to create arbitrary types.
irb(main):002:0> YAML.load("on: yes")
=> {true=>true}
Oh.https://github.com/crdoconnor/strictyaml/blob/master/FAQ.rst...
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.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.
Most people don't use these features.
But it's completely unusable for the Real World (tm) because strings cannot contain the '[' and ']' characters AND YET there is no mechanism for escape sequences. What if my data legitimately contains those two characters???
That's just the default string type. I started out with escaping but noticed it's a lot of complexity that is rarely needed (not for my own use case, which is accounting, inventory, and some web apps which don't need it).
The advantage of not having escaping is easier seds and greps which don't miss the field boundaries.
The important concept though is that arbitrary datatypes elements can be added by the user of an API implementation (the python library already offers that). The datatypes define their lexical syntax, like in perl6. I will also declare more "default" datatypes and might include a C-like string after enough consideration.
What you implemented there isn't a serialization format, it's a SQL DSL. Any time you implement a DSL, the first question should always be: "Have you considered S-Exprs?". If s-exprs do the job, then you just saved yourself having to implement a ton of stuff, including 90% of a spec.
I really wish there was a more popular middle-ground between YAML and JSON. People use YAML because it's the next step up from JSON if you need comments, etc., but I think most purposes would be better served by the likes of JSON5, HJSON, or TOML (for example) if only any of those were as popular as JSON and YAML.
I implemented a YAML parser from spec last month. It (YAML) goes to great lengths to provide human-friendly features, trading off computer-friendliness to an fairly extreme extent.
Eliminating 'plain' scalars (unquoted strings-as-values), folded multiline literals, tags, anchors/aliases, and possibly directives, as a sort of reduced yaml would make the language a lot less silly for the kinds of things a lot of people end up using it for.
They may have a slight advantage over the default spec of YAML but they don't stack up well against YAML with the features you mentioned removed.
I really don't think an entirely new standard is warranted.
I think YAML is more widely-used than it would otherwise be, in a broader variety of domains, simply because the only popular alternative doesn't have comments.
I'm not drawing from this any sort of conclusion that we should try to push one of these alternatives as viable, just lamenting the state of things.
We use it for:
1. test case specifications we use for unit tests suits that must run across multiple languages.
2. DSL for business processes
But I think most uses of YAML are basically just a much more flexible JSON.
I would like a clearly documented YAML subset that left out some of the more complex stuff and avoided a few 'more than one way to do it' features. That would go a long way to removing some of the criticism of YAML with very little cost in functionality.
My experience with YAML is that it's very temperamental with respect to /whitespace/ and that your editor might try to get too smart and damage the document.
JSON, if you see a pattern and follow the pattern, is likely to work.
JSON CAN be stored in a 'pretty' way, with extra whitespace, which makes it even more obvious how to format a document; that's frequently how I write out small bootstrap config files (IE the database connection string to get the main config from).
To copy-paste the example:
server
path: /core/www/
host: example.com
port: 80
service: true
proxy
host: proxy.example.com
port: 8080
authentication: plain
description
:Primary web-facing server
:Provides commerce-related functionality
server
...
proxy host="proxy.example.com" port=8080
authentication: plain
There's no character escaping, brackets, distinction between attributes and elements, data types (up to the one parsing the document how to decode values), etc. BOM-free UTF-8 is mandatory.It's the bare minimum for an extensible tree-based data structure, but I threw in three ways to assign values to nodes to help craft smaller documents. Turns out it's hugely important to be able to assign multiple child nodes on the same line as the parent for certain classes of documents.
My implementation of BML uses my string library, so I can't offer a portable parser. But it shouldn't take more than an hour or two to write a BML parser.
Still, my reference example is here: https://gitlab.com/higan/higan/tree/master/nall/string/marku... -- 177 lines for the base parser, which can also save back modified BML documents.
Downside is that I have no clue how to market it, and I hate writing documentation, so there's only a few people using it.
I looked for one some months ago and the closest I found was https://github.com/crdoconnor/dumbyaml, which is a parser implementation, not a standard. Out of projects approaching the issue from the opposite angle ("smarter JSON"), I think HOCON (https://github.com/typesafehub/config/blob/master/HOCON.md) is the most promising. Compared to Hjson (http://hjson.org/), it is less likely to confuse the user with how trailing commas are treated in unquoted strings and generally appears to not compromise on strictness for convenience.
That said, I agree with TillE: as soon as a configuration file format I work on needs any logic or expressions I will strongly consider an embedded scripting language like Lua or Tcl in order to avoid instantiating Greenspun's tenth rule for configuration.
That's the goal of dotset (https://github.com/espadrine/dotset).
If you want to use it for complex things, sure, there's no end of potential features. If you need some logic with your data, I like Lua.
Say some more about this. I look at YAML as a way to do data exchange, like using JSON/SON. How does Lua fit into this?