News for hackers. Stuff that matters.
Re:YAML: probably not so great after all (2017) by chx on Wednesday June 20, 2018 @03:14PM (#17358722)
Drupal 8 uses YAML* as its configuration language because JSON doesn't support comments. That simple. Thank you for YAML, it does deliver for us: it's human readable and it's easy to parse (see below).

* I mean, it uses an ill defined subset of YAML. The definition is "whatever the Symfony YAML parser supports".

Re:YAML: probably not so great after all (2017) by wwweston on Wednesday June 20, 2018 @06:03PM (#17360225)
You know what else is human readable, easy to parse if you're using PHP, and supports comments?

PHP.

I understand why some languages rely on common configuration file formats.

I don't understand why the popular dynamic script-y languages don't more commonly use the natively-expressable associative/list data structures that they're famous for making convenient.

Re:YAML: probably not so great after all (2017) by kakwa_ on Thursday June 21, 2018 @02:54AM (#17362727)
Using includes/imports is not the greatest idea ever.

Your configuration file is one of your program interface. It's something that must be well define. If your configuration file is a programing language this interface is not that well defined.

Also you expose yourself to all kind of weird bugs because some (too smart for their own good) people will monkey patch your software using it.

It adds a lot of unnecessary stuff in the configuration file, things like ';' or '$' are not really useful.

Lastly, common configuration file format are good because there are... common. You can have 2 pieces of software in 2 different languages accessing the same configuration file. A common example of that is configuration management, There are a lot of modules/formula in salt/ansible/puppet/chef doing fine parsing of the configuration files and permits fine grain settings, and I'm not mentioning augeas. If your configuration is a php/python/perl/ruby file good luck with that.

I know it's really common for php applications to do configuration files in php, but frankly, it's a bit annoying.

Re:YAML: probably not so great after all (2017) by Sean1708 on Thursday June 21, 2018 @05:22AM (#17363404)
> If your configuration file is a programing language this interface is not that well defined.

While I do agree with the rest of your comment I don't think they were advocating using the full language for configuration, just the maps/arrays/etc. (e.g. Python's `literal_eval`).

Re:YAML: probably not so great after all (2017) by kakwa_ on Thursday June 21, 2018 @03:17PM (#17368412)
true, but some user will use the full language.

Something like:

config = {'key1': 'value1', 'key2': 'value2'}

could be written as:

config = {}

config['key1'] = 'value1'

config['key2'] = 'value2'

With large chunk possible between the 3.

It basically transforms the configuration file into an API like any library, which is not really what you want for an end user program.

Re:YAML: probably not so great after all (2017) by wwweston on Thursday June 21, 2018 @08:04PM (#17370210)
If a key objection/perceived threat is that this might give someone an insertion point they're not meant to use for code ... well, let's consider that we're talking about applications distributed as interpreted language source here. Disallowing code-as-config isn't even closing the door of this particular barn after the horse has left, it's putting two strands of police line tape across the bottom half of the gap where the door was never installed and hoping any equines thinking of passage politely consider the message in case it hadn't already occurred to them which side of the entrance they preferred to be on.

Consider this: Design and optimize for the common case.

Why do we have config files? Because developers actually want a place dedicated to simple or structured application configuration data, for which PHP assignments with arrays + primitives can function at least as effectively as JSON. Most developers would prefer that config data get loaded quickly so the application can get on to doing actual app-y things. Using the language for this means you're parsing at least as fast as you can interpret and you can also take advantage of any code caching that's part of your deployment (especially nice in the PHP-likely event that config settings would be reloaded with every request).

Abuse isn't likely to be the common case. The end users you invoked certainly aren't going to be the ones looking for opportunities to insert code over data. Developers have other places to put code and, as mentioned, probably actually want a place dedicated to data. You're still right that of course someone will do it, just like someone will inevitably create astronaut architecture hierarchy monstrosities in any language with classical inheritance or make potentially hidden/scary changes to language function using metaprogramming facilities.

But potential for abuse doesn't automatically mean a feature should be disallowed.

A lot of the time it's better to let people who can be circumspect have the benefits of a potential approach, and if somebody thinks they need to solve a problem by using a technique that's arguably abuse, well, let them either find out why it's a bad idea or enjoy having solved their problem in an unusual way. Not the end of the world. Possibly even legit.

Re:YAML: probably not so great after all (2017) by derefr on Wednesday June 20, 2018 @06:20PM (#17360357)
You can use arbitrary tools to programmatically generate YAML (or JSON, or XML, any of the other "data only" formats.) This allows for tools to drive other tools by generating a spec file and feeding it in. See e.g. Kubernetes for a good example of that.

There's no language that I'm aware of that can natively generate PHP syntax, and there's no common multi-language-platform library for generating PHP syntax. I think that's most of the reason.

To contradict myself, though: Ruby encodes Gemfiles and Rakefiles as Ruby syntax. And Elixir encodes Mixfiles, Mix.Config files, Distillery release-config files, and a bunch of other common data formats as Elixir syntax.

And, of course, pretty much every Lisp just serializes the sexpr representation of the live config for its config format (which means that, frequently, a lot of Lisp runs code at VM-bootstrap time, because people write Turing-complete config files.)

Re:YAML: probably not so great after all (2017) by wwweston on Wednesday June 20, 2018 @07:23PM (#17360800)
> There's no language that I'm aware of that can natively generate PHP syntax

This is a solid argument against using PHP (or any such language) as a cross-language data interchange format. There are others :) And I totally agree you want a language independent format for anything you might have to feed across an ecosystem of tools.

For a PHP-system generating/altering its own config files... PHP's `var_export` generates a PHP-parseable string representation of a variable (though it sadly doesn't use the short array syntax).

Turing-complete config files probably have some hazards, like Lisp itself does. YMMV regarding whether those hazards can be avoided by circumspect developers or need to be fenced off.

Re:YAML: probably not so great after all (2017) by scrollaway on Wednesday June 20, 2018 @08:49PM (#17361185)
You don't know when you'll need to generate or parse your config files with something that either can't read, write or execute your language.

Django's settings.py sucks. I've used Django since the 0.9 days. It's extremely impractical and needs to be worked around constantly.

Re:YAML: probably not so great after all (2017) by JdeBP on Thursday June 21, 2018 @08:57AM (#17364629)
This, and the security problems of executable code as configuration, are why the OpenBSD people mandate that /etc/rc.conf is not general-purpose shell script, and why the systemd people mandate that /etc/os-release is similarly not. People want to be able to parse configuration files like this with something other than fully-fledged shell language interpreters; and they want these things to not be vectors for command injections.

* https://unix.stackexchange.com/a/433245/5132

Re:YAML: probably not so great after all (2017) by LaGrange on Thursday June 21, 2018 @09:20AM (#17364803)
Settings.py is uniquely bad, though, IMO because it tries to be a badly defined dict(), instead of exposing proper configuration interfaces. Ruby config files are common and usually fairly great, see for example the Vagrantfiles.

And you won't have to generate your config files (parsing, maaaaaybe), because those needs are covered by the fact that the files are programs. They are _already_ generating a configuration.

Re:YAML: probably not so great after all (2017) by derefr on Thursday June 21, 2018 @01:28PM (#17367289)
> And you won't have to generate your config files (parsing, maaaaaybe), because those needs are covered by the fact that the files are programs. They are _already_ generating a configuration.

Yes, theoretically, if settings.py was a "generator" format that you ran as a pre-step (like you do to get parser-generators like Bison to spit out source files for you to work with), and this generator actually spat out something like a settings.json, and all the rest of the infrastructure actually dealt with the settings.json rather than the generator, then, yes, it wouldn't matter. Tools in other languages could just generate the settings.json directly.

As it stands, none of those things are true, so tools in other languages actually need to do something that outputs settings.py files.

Re:YAML: probably not so great after all (2017) by LaGrange on Thursday June 21, 2018 @02:13PM (#17367798)
Galaxy brain: if your config is programmable, it can read whatever terrible configuration format you want. That means my settings.py (yes, I'm forced to use Django) is configured via environment, which is populated by k8s from - gasp - JSON files.

That means that if I wanted to configure Vagrant with JSON, there is no force in the universe that could stop me.

If the config file is actually a normal program, then it can do normal program things, then any benefit from using JSON instead is nullified by the fact that you can still use JSON. In turn, if your tools primary configuration is via a more limited settings, you're stuck with it. Not even "generators in other languages" allow comparable runtime flexibility.

Re:YAML: probably not so great after all (2017) by piva00 on Thursday June 21, 2018 @04:27AM (#17363156)
Yup, totally agree with you, settings.py has always been a pain in the ass. Not really an acute one but the kind that is uncomfortable but not enough to make you do something about it.
Re:YAML: probably not so great after all (2017) by dotancohen on Thursday June 21, 2018 @03:25AM (#17362881)
> There's no language that I'm aware of that can natively generate PHP syntax.

Actually, I've had to use PHP to output a PHP configuration array for a project that required config in PHP.

`var_export($foo)` will output valid PHP code for creating the array $foo. In my case I was doing horrible things to create the array in my pseudo-makefile, then using `var_export()` to output the result. Note that you can run php from the Bash CLI with the `-r` flag, which helps.

Re:YAML: probably not so great after all (2017) by kevin_thibedeau on Wednesday June 20, 2018 @11:40PM (#17361936)
Tcl works well for configuration files. You can strip away the extraneous commands in a sub-interpreter to prevent Turing completeness and add infix assignment to remove the monotony of the set command and what you get is a nice config format. If you need more power in the future you just relax some of the restrictions and use it as a script without breaking existing files.
Re:YAML: probably not so great after all (2017) by Jach on Wednesday June 20, 2018 @06:34PM (#17360470)
People get really upset when they have to type "array(" instead of "[" or "{" (pre-PHP 5.something) and quotes instead of no quotes (and punting the character escape problem to something else) I guess.

Using code-as-data works really well in Lisp-like languages. Reading a Clojure project's project.clj file or a Lisp project's project.asdf file is pretty pleasant. A programming language's choice in how it decides to handle library config info for building and specifying dependencies (XML, makefiles, JSON, YAML, INI, nothing, etc...) will be a good indicator for the culture of the language around config files in general. Composer for PHP only came out in 2012.

Re:YAML: probably not so great after all (2017) by akavel on Wednesday June 20, 2018 @06:59PM (#17360661)
Interestingly, the Lua programming language actually evolved from configuration files: https://www.lua.org/history.html (and is still officially deemed useful for writing them)
Re:YAML: probably not so great after all (2017) by spc476 on Wednesday June 20, 2018 @09:46PM (#17361411)
I use Lua for configuration files for both personal and work related projects [1]. You get comments and the ability to construct strings piecemeal (DRY and all that). It's easy to sandbox the environment, and while you can't protect against everything (basically, a configuration script can go into an infinite loop), if someone unauthorized does have access to the script, you have bigger things to worry about.

[1] An example: https://github.com/spc476/mod_blog/blob/master/journal/blog....

Re:YAML: probably not so great after all (2017) by dottrap on Wednesday June 20, 2018 @11:40PM (#17361942)
You can set a count hook to defend against infinite loops.

Lua is great.

Re:YAML: probably not so great after all (2017) by DonHopkins on Wednesday June 20, 2018 @07:38PM (#17360883)
That was also one of the rationales behind TCL's design.

John Ousterhout explained in one of his early TCL papers that, as a "Tool Command Language" like the shell but unlike Lisp, arguments were treated as quoted literals by default (presuming that to be the common case), so you don't have to put quotes around most strings, and you have to use punctuation like ${}[] to evaluate expressions.

TCL's syntax is optimized for calling functions with literal parameters to create and configure objects, like a declarative configuration file. And it's often used that way with Tk to create and configure a bunch of user interface widgets.

Oliver Steel has written some interesting stuff about "Instance-First Development" and how it applies to the XML/JavaScript based OpenLaszlo programming language, and other prototype based languages.

Instance-First Development: https://blog.osteele.com/2004/03/classes-and-prototypes/

>The equivalence between the two programs above supports a development strategy I call instance-first development. In instance-first development, one implements functionality for a single instance, and then refactors the instance into a class that supports multiple instances.

>[...] In defining the semantics of LZX class definitions, I found the following principle useful:

>Instance substitution principal: An instance of a class can be replaced by the definition of the instance, without changing the program semantics.

In OpenLaszlo, you can create trees of nested instances with XML tags, and when you define a class, its name becomes an XML tag you can use to create instances of that class.

That lets you create your own domain specific declarative XML languages for creating and configuring objects (using constraint expressions and XML data binding, which makes it very powerful).

The syntax for creating a bunch of objects is parallel to the syntax of declaring a class that creates the same objects.

So you can start by just creating a bunch of stuff in "instance space", then later on as you see the need, easily and incrementally convert only the parts of it you want to reuse and abstract into classes.

What is OpenLaszlo, and what's it good for? http://www.donhopkins.com/drupal/node/124

Constraints and Prototypes in Garnet and Laszlo: http://www.donhopkins.com/drupal/node/69

Re:YAML: probably not so great after all (2017) by pjmlp on Friday June 22, 2018 @08:05AM (#17373300)
In our Tcl based application server (many eons ago), we followed exactly that approach.

All configuration files were Tcl data structures that were sourced on server start.

Re:YAML: probably not so great after all (2017) by krapp on Wednesday June 20, 2018 @06:13PM (#17360306)
>I don't understand why the popular dynamic script-y languages don't more commonly use the natively-expressable associative/list data structures that they're famous for making convenient.

You picked the wrong language... PHP comes with its own JSON parser. And INI and XML and even CSV.

But, the reason is that, generally, you want config files to describe data or state only. Yes, you could just make your config native code, but then the temptation to add functions and methods and logic to that becomes irresistible and soon your config is an application that needs its own config.

Config formats need to be simple, and preferably not Turing complete.

Re:YAML: probably not so great after all (2017) by user5994461 on Wednesday June 20, 2018 @07:25PM (#17360811)
Any configuration will eventually become a programming language.

See The Configuration Complexity Clock. https://mikehadlow.blogspot.com/2012/05/configuration-comple...

Re:YAML: probably not so great after all (2017) by krapp on Wednesday June 20, 2018 @10:09PM (#17361521)
Just because it's common doesn't mean it should be encouraged by writing your config in native code to begin with.

INI is still simple, and JSON doesn't support logic, so the madness can be held at bay at least for a time.

XML and s-expressions are lost causes, though.

Re:YAML: probably not so great after all (2017) by zmmmmm on Wednesday June 20, 2018 @07:58PM (#17360986)
Because it's just in general incredibly short sighted to think that your config file is never going to be read by code written in another language.

There's also an argument about whether making configuration files able to execute arbitrary code is a good idea. You get straight into the JavaScript 'eval' problems which we've spent a decade escaping.

Re:YAML: probably not so great after all (2017) by dcbadacd on Thursday June 21, 2018 @02:54AM (#17362728)
Arbitrary code execution in configuration files has caused a few vulnerabilities in Wordpress extensions already, so yes, it's a terrible idea.
Re:YAML: probably not so great after all (2017) by ramses0 on Wednesday June 20, 2018 @06:31PM (#17360432)
I think some of it is PLOP (Principle of Least Power).

$CFG = random() > 0.5 ? "yes" : "no";

...is likely "too powerful". It'd be nice if there were ways in certain programming languages to do something like "drop privileges" to avoid loops, function calls, external access, etc.

Re:YAML: probably not so great after all (2017) by njbooher on Wednesday June 20, 2018 @07:11PM (#17360731)
The makers of Drush, the cli for Drupal, subscribed to your line of thinking in the early versions and inventory items were defined in PHP files. Migrating from that will be interesting.
Re:YAML: probably not so great after all (2017) by Annatar on Thursday June 21, 2018 @03:24AM (#17362874)
Because that forces the end user, who might not know anything about the programming language one’s application is written in to wrestle with the low level implementation details. In the words of Keith Wesolowski, the programmer assumes that the end user is a “Linux superengineer”, which is almost always a wrong assumption to make.
Re:YAML: probably not so great after all (2017) by chx on Thursday June 21, 2018 @01:56AM (#17362482)
I have linked this https://groups.drupal.org/node/159044 elsewhere. Please note PHP was considered.
Re:YAML: probably not so great after all (2017) by pjmlp on Friday June 22, 2018 @08:03AM (#17373290)
Fully agree with you, I have done so multiple times.
Re:YAML: probably not so great after all (2017) by DonHopkins on Wednesday June 20, 2018 @07:23PM (#17360799)
I totally agree that in the ideal world, JSON should support comments. I yearn for them, and none of the in-band work-arounds or post-processing tools are acceptable substitutes.

But to play the devil's advocate, how would JSON be able to support round-tripping comments like XML can, since <!-- comments --> are part of the DOM model that you can read and write, while JSON // and /* comments */ are invisible to JavaScript programs. There's nowhere to store the comments in the JSON object model, which you would need to be able to write them back out later!

On important feature of JSON is being able to read and write JSON files with full fidelity and not lose any information like comments. XML can do that, but JSON can't. To fix that you'd have to go back and redesign (and vastly complicate) fundamental JavaScript objects and arrays and values, to be as complex and byzantine as the DOM API.

The less-than-ideal situation we're in isn't JSON's fault or JavaScript's fault, because JSON is just a post-hoc formalization of something that was designed for a different purpose. But JSON is rightly more popular than XML, because it's extremely simple, and nicely impedance matched with many popular languages.

YAML suffers from the same problem as JSON that it can't round-trip comments like XML can, but it fails to be as simple as JSON, is almost as complex as XML, and doesn't even map directly to many popular languages (as the article points out, you can't use a list as a dict key in Python, PHP, JavaScript, or Go, etc).

You can sidestep some of JSON's problems by representing JSON as outlines and tables in spreadsheets, without any need for syntax and sigils like brackets, braces, commas, no commas, quoting, escaping, tabs, spaces, etc, but in a way that supports rich formatted comments and content (you can even paste pictures and live charts into most spreadsheets if you like), and even dynamic transformations with spreadsheet expressions and JavaScript.

See my comments about that in this and another article: https://news.ycombinator.com/item?id=17360071 https://news.ycombinator.com/item?id=17309132

Re:YAML: probably not so great after all (2017) by Mikhail_Edoshin on Friday June 22, 2018 @04:30AM (#17372408)
> "YAML ... is almost as complex as XML"

In fact YAML is probably more complex than XML; the specification of YAML, when I print it into PDF, is about three times as long as that of XML 1.0. (And XML 1.0 also describes DTD, which is kind of a simple type validation for XML and thus includes much more than just serialization syntax.)

Re:YAML: probably not so great after all (2017) by int_19h on Thursday June 21, 2018 @04:09AM (#17363054)
> But to play the devil's advocate, how would JSON be able to support round-tripping comments like XML can, since <!-- comments --> are part of the DOM model that you can read and write, while JSON // and /* comments */ are invisible to JavaScript programs.

It doesn't support it for whitespace in general (if you deserialize into JS object model or equivalent), so why would it be any different for comments specifically? It's just not a design goal of the format.

Although, of course, it's quite possible to have a JSON parser that preserves representation. It'll just have a non-obvious mapping to the host language because of all the comment and whitespace nodes etc.

Re:YAML: probably not so great after all (2017) by tlocke on Thursday June 21, 2018 @03:36AM (#17362918)
Zish https://github.com/tlocke/zish supports comments (but they're not round-trip comments) and also extra data types such as timestamp and bytes.

It's still in its early stages, so if anyone's got any comments I'm interested in hearing them :-)

Re:YAML: probably not so great after all (2017) by aepiepaey on Thursday June 21, 2018 @06:36AM (#17363731)
> YAML suffers from the same problem as JSON that it can't round-trip comments like XML can, [...]

While not mandated by the YAML specification, it doesn't prevent creation of a parser that round-trips comments.

In fact, the ruamel.yaml project for Python provides one.

Re:YAML: probably not so great after all (2017) by rhacker on Wednesday June 20, 2018 @08:51PM (#17361194)
I'm kinda sad that JSON has been struggling for like 15 years to get comments. Is there like some kind of gestapo that's saying no or something? All it takes is for the maintainers of probably 15 popular libraries to start handling comments.

At the end of the day I'm sure the reason we don't have JSON comments is somewhere listed in this page: xkcd.com/927/

Re:YAML: probably not so great after all (2017) by JonathonW on Wednesday June 20, 2018 @09:36PM (#17361362)
I'm aware of at least three JSON libraries that at least can accept comments (Gson in lenient mode, Json.NET, and json-cpp are the ones I've used personally that do)-- it's hard to convince everyone that JSON needs comments, though, and comments are of limited utility if it's not guaranteed that they'll parse everywhere.

But you really only need comments in JSON if you're doing stuff like storing configuration in JSON, and JSON's too fiddly in general to be a great config file format (too easy to do something like forget a comma; no support for types beyond object, array, (floating point) number, and string). Something more like YAML without the wonky type inference would be better, IMO.

Re:YAML: probably not so great after all (2017) by ajmurmann on Wednesday June 20, 2018 @09:13PM (#17361271)
I believe Douglas Crockforf used to make the argument that JSON is not meant for human consumption and thus shouldn't be changed to better serve humans. I personally wish hjson (https://hjson.org) were to get more traction. I prefer it over both JSON and YAML.
Re:YAML: probably not so great after all (2017) by jasonjayr on Wednesday June 20, 2018 @09:23PM (#17361309)
It was Crockford. Directly from him:

> I removed comments from JSON because I saw people were using them to hold parsing directives, a practice which would have destroyed interoperability. I know that the lack of comments makes some people sad, but it shouldn't.

https://plus.google.com/+DouglasCrockfordEsq/posts/RK8qyGVaG...

Re:YAML: probably not so great after all (2017) by Mikhail_Edoshin on Friday June 22, 2018 @06:43AM (#17372944)
Well, then why not to allow a trailing comma in lists and objects? Computers don't care and they would even be happier, because they can then just pour array and object members with a trailing comma without concerning themselves whether this is the last member or not. (Dijkstra's train toilet problem comes to mind.) Also compare with XML, where each element is self-contained.

And why to model JSON syntax closely after JavaScript literal object syntax (which is actually more convenient, by the way) which, being taken from mainstream programming languages, naturally evolved to be written by humans in small amounts not by computers in large dumps? :)

Re:YAML: probably not so great after all (2017) by skybrian on Wednesday June 20, 2018 @05:31PM (#17359983)
VS Code uses JSON with comments for config files. [1]

Technically, this is not JSON. You won't be able to use a standard JSON parser without stripping comments first. But you can use a simple, JSON-like language with comments for config.

[1] https://code.visualstudio.com/docs/languages/json#_json-with...

Re:YAML: probably not so great after all (2017) by EamonnMR on Wednesday June 20, 2018 @06:10PM (#17360288)
> you can use a simple, JSON-like language with comments for config.

YAML can be employed as a simple JSON-like language with comments.

Re:YAML: probably not so great after all (2017) by crooked-v on Wednesday June 20, 2018 @06:15PM (#17360325)
> simple

YAML is much, much more complicated than JSON.

Re:YAML: probably not so great after all (2017) by hk__2 on Wednesday June 20, 2018 @06:39PM (#17360503)

    > simple
    YAML is much, much more complicated than JSON.
Quoting a single word from the parent’s sentence is misleading. The sentence "YAML can be employed as a simple JSON-like language with comments." is true because JSON is YAML, so you can parse a JSON file with #-comments using a YAML parser.
Re:YAML: probably not so great after all (2017) by skybrian on Wednesday June 20, 2018 @07:32PM (#17360847)
The parser is not simple, though, and that's what counts.
Re:YAML: probably not so great after all (2017) by bdhess on Wednesday June 20, 2018 @08:41PM (#17361156)
Most YAML users don't need to look at the source for a YAML parser. I appreciate elegant simplicity, but I don't think parser complexity is the most important metric by which to judge a data interchange format.
Re:YAML: probably not so great after all (2017) by skybrian on Thursday June 21, 2018 @01:46AM (#17362445)
If you use a YAML parser to parse JSON-with-comments, it will accept many inputs that don't correspond to JSON-with-comments, and furthermore is likely to report syntax errors that don't make sense to a user who only knows JSON.

So, this unnecessary parser complexity is a usability issue. You should use a parser for the config language you actually intend to support.

Re:YAML: probably not so great after all (2017) by spankalee on Wednesday June 20, 2018 @08:16PM (#17361072)
JSON5 is also a great alternative: https://json5.org/

Supports comments, trailing commas, single quotes, multi-line strings, and more number formats.

Re:YAML: probably not so great after all (2017) by nojvek on Wednesday June 20, 2018 @10:52PM (#17361714)
I really wished json5 would support optional commas as well. If you have a new line, no comma needed. So you can do

[

1

2

3

]

New lines used by humans, computers should do a good job as well.

Re:YAML: probably not so great after all (2017) by adamkruszewski on Thursday June 21, 2018 @07:30AM (#17364049)
It looks very like an s-expression. Maybe we should go back to Lisp for our data encoding? (and to our code when we are at it? ;))
Re:YAML: probably not so great after all (2017) by Sean1708 on Thursday June 21, 2018 @09:09AM (#17364696)
Re:YAML: probably not so great after all (2017) by spiralx on Friday June 22, 2018 @12:43PM (#17375397)
Well you could use CSON, which uses CoffeeScript notation that allows for constructs such as:

required: [

  'firstName'

  'lastName'
]

which is the same as:

{

  "required": [

    "firstName",

    "lastName"

  ]
}

in JSON :)

Re:YAML: probably not so great after all (2017) by spankalee on Thursday June 21, 2018 @12:27AM (#17362166)
That's not a subset of JavaScript though.
Re:YAML: probably not so great after all (2017) by craigds on Wednesday June 20, 2018 @08:57PM (#17361215)
Sublime Text does too.
Re:YAML: probably not so great after all (2017) by pacala on Wednesday June 20, 2018 @10:19PM (#17361564)
Try https://jsonnet.org/. Supports comments, plus a handful of additional useful features.
Re:YAML: probably not so great after all (2017) by nojvek on Wednesday June 20, 2018 @10:48PM (#17361691)
Jsonnet is awesome. We use it to generate our yaml files for kubernetes. YAML isn’t easy to parse, nor is it very flexible as a templating language. It gets cumbersome very quickly.

Jsonnet is a relief. Kubernetes should have been a dumb json config from the get go. JSON is ridiculously simple to parse and emit. It has huge interoperability as well with lots of programming languages.

Re:YAML: probably not so great after all (2017) by pests on Thursday June 21, 2018 @03:55AM (#17363000)
Kubenetes never intended to get stuck on YAML. The CNCF is backing Ksonnet which is Jsonnet for k8s if you haven't seen it before.
Re:YAML: probably not so great after all (2017) by alessioalex on Thursday June 21, 2018 @08:15AM (#17364379)
Oh man, you just made my day. Comments, imports and mixins, I just had an 'evrika' moment.

P.S. You Romanian by any chance?

Re:YAML: probably not so great after all (2017) by merb on Wednesday June 20, 2018 @05:16PM (#17359863)
well there is also toml and hocon (json supersets) which are "yaml like"
Re:YAML: probably not so great after all (2017) by benatkin on Wednesday June 20, 2018 @05:53PM (#17360141)
TOML is more like ini than YAML.

I don't like it because it uses the = symbol which seems imperative rather than declarative. (Same with HCL, it might be a nitpick but these are languages I'm going to be using all the time.)

HOCON is interesting but at first glance it seems it might be too ambiguous for my tastes, because like YAML, because it supports both js-style ("//") and shell-style ("#") comments.

JSON plus comments is beautiful because it adds minimally to an unambiguous language which lends itself to automatic formatting (stringificiation).

Re:YAML: probably not so great after all (2017) by colatkinson on Wednesday June 20, 2018 @06:30PM (#17360426)
I'd argue that = only feels imperative if you're used to imperative languages. Prolog and Haskell, both of which focus on being declarative, also both use the equals sign.
Re:YAML: probably not so great after all (2017) by benatkin on Wednesday June 20, 2018 @07:34PM (#17360858)
Fair enough. It still seems overkill to me though. A ":" seems much more unassuming than an "=".
Re:YAML: probably not so great after all (2017) by user5994461 on Wednesday June 20, 2018 @07:28PM (#17360831)
Don't forget HJSON if you want a json clone with comments. https://hjson.org/
Re:YAML: probably not so great after all (2017) by chx on Wednesday June 20, 2018 @05:20PM (#17359891)
TOM: Initial release 23 February 2013; 5 years ago

Drupal 8 file format discussion was in 2011, predating it by two years. https://groups.drupal.org/node/159044

Re:YAML: probably not so great after all (2017) by kpil on Thursday June 21, 2018 @01:55AM (#17362479)
Is there a yaml parser that preserves comments and a writer that manages to write them back though?
Re:YAML: probably not so great after all (2017) by TimZehta on Thursday June 21, 2018 @10:58AM (#17365734)
The parser linked from the article does: https://github.com/crdoconnor/strictyaml
Re:YAML: probably not so great after all (2017) by jiveturkey on Wednesday June 20, 2018 @05:00PM (#17359727)
> JSON doesn't support comments

eh?

{ "firstName": "John", "lastName": "Smith", "comment": "foo", }

I know it isn't the same as #comments, but who cares really.

Re:YAML: probably not so great after all (2017) by Smaug123 on Wednesday June 20, 2018 @05:09PM (#17359800)
The trouble there is that your comments come in-band. What if you're trying to serialise something and you don't have the power to insist that it's not a dictionary with "comment" as a key?
Re:YAML: probably not so great after all (2017) by hexane360 on Wednesday June 20, 2018 @05:05PM (#17359768)
It seems the main difference is your comments are all parsed and loaded into memory with the file, while official comments aren't.
Re:YAML: probably not so great after all (2017) by dharmab on Wednesday June 20, 2018 @05:12PM (#17359821)
How do I do something like:

{ # comment with a note about the value of foo "foo": "bar", # comment with a note about the value of baz "baz": "qux" }

Without driving myself and future readers insane with fooComments and bazComments?

What if I need a multiline comment explaining a yak-shaving story for why a key is set to a certain value?

What if the object in question is a set of keyword arguments, and adding new fields changes the behavior of whaever is parsing the document?

Re:YAML: probably not so great after all (2017) by mottosso on Wednesday June 20, 2018 @05:24PM (#17359929)
Ok, I'll bite.

  {
    "#": "A foo variable",
    "foo": true,

    "#": "A bar variable",
    "bar": false
  }
Alternatively.

  {
    "# A foo variable": "",
    "foo": true,

    "# A multiline..": "",
    "# .. bar variable": "",
    "bar": false
  }
Presto!
Re:YAML: probably not so great after all (2017) by chx on Wednesday June 20, 2018 @05:42PM (#17360058)
Sigh. All I wanted to do is to say thanks for the YAML standard -- comments are important but not the only problem with JSON. And truly I can't be expected to remember all of this discussion from like six plus years ago. One thing I remember though, it the trailing comma problem -- we upstreamed a grammar change to Doctrine annotation so "foo, bar," is OK because PHP arrays accept that and it's bonkers trying to code a mostly PHP system without trailing comma support. Also, JSON is no fun to write , you need to have [] {} all correct where YAML is much easier. The less sigils the better and most of Drupal YAMLs only use the dash, the colon and the quote. This is the grave mistake Doctrine committed as well, instead of simple arithmetic (>=1.0) they used mysterious sigils in version specification (~1.0). Drupal is in the business of constantly accepting new contributors and (~R∊R∘.×R)/R←1↓ιR is not newbie friendly, no matter how you slice and dice it. There are certainly advantages of sigil heavy languages like APL and Perl but the scare factor is too high.
Re:YAML: probably not so great after all (2017) by jiveturkey on Wednesday June 20, 2018 @05:58PM (#17360189)
fair enough, but then you probably shouldn't have led off your earlier comment with "that simple".
Re:YAML: probably not so great after all (2017) by goatlover on Wednesday June 20, 2018 @05:59PM (#17360200)
That's just ugly and you're mixing your comments with the data structure, which is potentially confusing. Also, Jason requires a lot more typing. I don't want to have to manually add in all the brackets, quotes and commas when editing config a file.
Re:YAML: probably not so great after all (2017) by mypalmike on Wednesday June 20, 2018 @11:16PM (#17361822)
Presto! You have a duplicate key in the first example.

Also...

  print (json.dumps(json.loads(js_data), indent=2))

  {
    "bar": false,
    "foo": true,
    "# A multiline..": "",
    "# .. bar variable": "",
    "# A foo variable": ""
  }
Presto! ;-)
Re:YAML: probably not so great after all (2017) by trynewideas on Wednesday June 20, 2018 @05:05PM (#17359769)
> who cares really

the person who came up with HOCON, probably