6 ms·
Have you hear of YAML?
by fbn79 8y ago
Have you hear of YAML?
- mbostock 8y agoYes. YAML would be more verbose and require more precise (error-prone) syntax. See this thread: https://twitter.com/mbostock/status/1075135178014482432 https://twitter.com/mbostock/status/1075135178014482432
- blauditore 8y agoYou can write YAML much more concisely though: root parent foo: 1 bar: 1 Syntax details might be off from the top of my head, but the example in the tweet is a bit overblown.
- mbostock 8y agoThe thread I linked describes the limitations of the approach you suggest, in particular, the ability to associate metadata not just with leaf nodes but also internal nodes, and not requiring the names of children to be unique. Of course you can express hierarchies in YAML, but the result ends up being more verbose and more prone to syntax errors; the point of comma-separated trees is to be easier to read and edit.
- tracker1 8y agoI don't think comma separated trees are easier to read... in fact, I think they're quite a bit harder. I will say it might be easier to write. do string quoting, quote escaping and newline embedded in a quoted string work?
- pgt 8y agoHave you heard of S-expressions? Whitespace optional: (World (Asia (China 1409517397) (India 1339180127) (Indonesia 263991379))) With an editor that supports Paredit or Parinfer, it's impossible to create an invalid tree, because you manipulate the structure of the tree (nodes and leaves) instead of manipulating error-prone text.
- mbostock 8y agoParinfer is very cool! If you’re willing to use a custom editor for trees, you can clearly offer better usability than a standard text editor. But having a usable data format for standard text editors is also nice.
- joseph8th 8y agoI'll see your snark and raise you two, throwing Emacs in for good measure. ;) Have you heard of org-export-json? [1] Have you heard of json.el? [2] [1] https://github.com/mattduck/org-toggl-py/blob/master/org-export-json.el https://github.com/mattduck/org-toggl-py/blob/master/org-exp... [2] http://tess.oconnor.cx/2006/03/json.el http://tess.oconnor.cx/2006/03/json.el
- pgt 8y agoHave you heard of XML? Not my first choice, though: <World> <Asia> <China>1409517397</China> <India>1339180127</India> <Indonesia>263991379</Indonesia> </Asia> </World>
- megous 8y agoHave you heard of JSON? [{"a": [{"b": "c"}]}]
- tracker1 8y agoYAML was designed as a superset of JSON with meaningful whitespace as part of the design, and optional string quotes. It's actually a REALLY good option for something like this. That said, the statement itself came off really snarky.
- henryluo 8y agoThere's also Mark Notation (http://marknotation.org/ http://marknotation.org/), which is also a tree notation. Less verbose than XML and JSON. {World {Asia {China '1409517397'} {India '1339180127'} {Indonesia '263991379'} } }
- dang 8y ago"Please don't post shallow dismissals, especially of other people's work." https://news.ycombinator.com/newsguidelines.html https://news.ycombinator.com/newsguidelines.html
- StevePerkins 8y agoYour snarky question is so far drawing a lot of snarky responses. However, the implied question here is absolutely valid: Why write your own flat-file format parser from scratch, when there's a multitude of battle-tested third-party libraries already in existence? I mean, if you're writing something very specialized or proprietary, that's one thing. But if you're simply proposing a generalized tree shape that looks like YAML, then why not indeed use YAML? I know it's tricky to write a YAML parser... but so what, why would you? There are already a ton of great ones.
- rsl7 8y agoIt's a superset of csv, what's the problem?
- breck 8y agoTwo good reasons to not use YAML for this interactive example: 1. intermediate steps in YAML are often invalid documents (breaks the update on every key press) 2. you have to be trained to write YAML. It is quite easy to make a syntax mistake with YAML if you aren’t used to writing it. Not good for an interactive experience
- tracker1 8y agoAnd arbitrary spaces with meaningful input isn't easy to make a mistake... my first thought, what about escaping newlines?