top | item 17360338

(no title)

jfaucett | 7 years 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?

discuss

order

Nadya|7 years ago

My 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|7 years 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.

krapp|7 years ago

It'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.

iainmerrick|7 years ago

none 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.

hahamrfunnyguy|7 years ago

That, 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.

jzelinskie|7 years ago

Shameless plug: I've been toying with a "format-agnositic jq" for all of these object like formats: 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
        }
      }

Jtsummers|7 years ago

(No (body (wants (to (write ‘(yaml))))))

FrenchyJiby|7 years ago

In TOML:

  nobody.wants.to.write = [ "YAML" ]

stephengillie|7 years ago

{"no":{"body":{"wants":{"to":{"write":["YAML"]}}}}}; // A one-liner.

falcolas|7 years ago

Invalid JSON though, due to the semi-colon and the comment.

yellowapple|7 years ago

One which happens to also work for YAML.

RandomInteger4|7 years ago

The last one to be honest. It's comforting in a way.

hzhou321|7 years ago

The problem is in the semantics

pgt|7 years ago

Please add the s-expr version?

weego|7 years ago

[deleted]