9 ms·
No: Body: Wants: To: Write: - YAML vs. <No> <Body> <Wants> <To> <Write>
by jfaucett 8y ago
No:
Body:
Wants:
To:
Write:
- YAML
vs.
<No>
<Body>
<Wants>
<To>
<Write>
<item>YAML</item>
</Write>
</To>
</Wants>
</Body>
</No>
vs.
{
"no" : {
"body" : {
"wants" : {
"to" : {
"write" : [ "YAML" ]
}
}
}
}
}
Which would you rather write?
- Jtsummers 8y ago(No (body (wants (to (write ‘(yaml))))))
- krapp 8y agoIt's a bit of a strawman, since none of your examples actually resemble valid config files and you're forcing them all to have the same indentation, when significant whitespace only matters in YAML.
- hahamrfunnyguy 8y agoThat, not too mention how often do you actually write data files by hand? Maybe a small sample file for testing, but beyond that all data is going to be read in from files or come from an API. JSON is not bad to write by hand. Simple XML isn't too bad either, but I still prefer JSON.
- iainmerrick 8y agoThis discussion seems to be largely about configuration files. Those usually are written and maintained by hand.
- hiyer 8y agoJSON doesn't have comments. If I want to know why a config has a particular value, I can write a comment to explain it in YAML or xml, just like I would do in code. Lack of comments is the primary reason I would not use json for anything that needs to be written or read by humans.
- iainmerrick 8y agonone of your examples actually resemble valid config files Neither does the YAML one? So? you’re forcing them all to have the same indentation I don’t know about you, but I always pretty-print JSON, just like I always indent my code no matter which language I’m using. In fact that’s one of the arguments in favour of significant whitespace -- you’re going to be indenting anyway, so why bother with the brackets? It’s not an argument everyone buys, but everyone still indents their code.
- reificator 8y ago> you’re going to be indenting anyway, so why bother with the brackets? Because brackets are explicit. Whitespace is implicit and difficult to distinguish without editor support.
- iainmerrick 8y agoI did say not everyone buys it! :) More seriously, the earlier comment complained that the indentation for the non-significant-whitespace examples was artificial. I’m saying it’s not artificial because in practice you would indent it.
- reificator 8y agoOh yeah I agree on that front entirely, I just wanted to comment on the other piece.
- Jedd 8y ago> > you’re going to be indenting anyway, so why bother with the brackets? > Because brackets are explicit. Whitespace is implicit and difficult to distinguish without editor support. I'm with parent on this one. Most people who complain about python's reliance on indentation still indent their code, and rely on the visual & editor hints (ie. they're profoundly confused when they muck up their indentation, but their brackets are still correct). But I digress. Whitespace is explicit in some (markup) languages, and there's nothing *plicitly wrong with that. If you're trying to do any kind of editing of a (markup) language that relies on sensible indentation with an editor that doesn't understand whitespace then you've probably got bigger problems.
- FrenchyJiby 8y agoIn TOML: nobody.wants.to.write = [ "YAML" ]
- Nadya 8y agoMy preference: # I guess you could put ["YAML"] if you need it as an array and not a string no.body.wants.to.write=YAML Easy to type, is on a single line, only breaks once you're so many layers deep that you need to scroll horizontally - but let's be real - if that happens the config isn't the problem but why is your program so complex? is the problem. Drawbacks of this are when the program is inconsistent. Was it `nobody.wants.to.write` or `no.body.wants.to.write`? Or alternatively, why is it `nobody.wants.to.read` but `no.body.wants.to.write`?
- jfaucett 8y ago> why is it `nobody.wants.to.read` but `no.body.wants.to.write`? Made me think there's also a big difference in what nobody prefers reading vs. what nobody prefers writing.
- weego 8y agodogshit, horseshit or cowshit; which would you rather eat for dinner?
- stephengillie 8y ago{"no":{"body":{"wants":{"to":{"write":["YAML"]}}}}}; // A one-liner.
- yellowapple 8y agoOne which happens to also work for YAML.
- falcolas 8y agoInvalid JSON though, due to the semi-colon and the comment.
- hzhou321 8y agoThe problem is in the semantics
- jzelinskie 8y agoShameless plug: I've been toying with a "format-agnositic jq" for all of these object like formats: https://github.com/jzelinskie/faq https://github.com/jzelinskie/faq Here's an interesting example of using bencode which is the object format for BitTorrent: curl -sL https://cdimage.debian.org/debian-cd/current/amd64/bt-cd/debian-9.4.0-amd64-netinst.iso.torrent | faq -f bencode 'del(.info.pieces)' -o json { "announce": "http://bttracker.debian.org:6969/announce", "comment": "\"Debian CD from cdimage.debian.org\"", "creation date": 1520682848, "httpseeds": [ "https://cdimage.debian.org/cdimage/release/9.4.0//srv/cdbuilder.debian.org/dst/deb-cd/weekly-builds/amd64/iso-cd/debian-9.4.0-amd64-netinst.iso", "https://cdimage.debian.org/cdimage/archive/9.4.0//srv/cdbuilder.debian.org/dst/deb-cd/weekly-builds/amd64/iso-cd/debian-9.4.0-amd64-netinst.iso" ], "info": { "length": 305135616, "name": "debian-9.4.0-amd64-netinst.iso", "piece length": 262144 } }
- pgt 8y agoPlease add the s-expr version?
- RandomInteger4 8y agoThe last one to be honest. It's comforting in a way.