by jfaucett · 8y ago · 0 comments
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? # 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`?
Made me think there's also a big difference in what nobody prefers reading vs. what nobody prefers writing.
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.
Because brackets are explicit. Whitespace is implicit and difficult to distinguish without editor support.
> 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.
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.
JSON is not bad to write by hand. Simple XML isn't too bad either, but I still prefer JSON.
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
}
} nobody.wants.to.write = [ "YAML" ]