From: why the lucky stiff Date: 2004-03-15T05:09:01+09:00 Subject: Re: YAML as configuration format Jamis Buck wrote: > Has anyone successfully used YAML as a configuration file format? I'm > sure it can be done--I'm not doubting that--but I'm curious as to the > recommended way of handling sequences. In XML, it's pretty > straightforward, but in YAML it seems a little less natural. In other > words: > > > > > > > okay. yeah, let's talk about this. first of all, i'm not clear on the above example and i'd like to know what you mean by the above. my assumptions of the above would be: 1. is a root-level element meant to enclose all tags pertinent to configuration. 2. tags represent configuration settings. `name' and `type' are an equivalent of key/value pairs. you are mapping a setting to its value? `name' would be a setting's name. honestly, i'm not sure what `type' means. 3. these s are expected to retain their order. are all three of these assumptions correct? consider #3 especially. is it pertinent that these stay in order? > can't be done directly in YAML. Instead (as far as my limited YAML > knowledge goes) it seems like you have to do: > > conf: > elements: > - one: type > - two: type > - three: type > well, how would you express these with ruby's arrays and hashes? yaml's structures are no different. i tend to use typing information to replace xml tags. to me it's more readable: --- !!conf - !!element {one: type} - !!element {two: type} - !!element {three: type} the types above are private types. they are temporary types which are temporary and could be replaced with domain types once you've got them officially worked out. i'm not suggesting that the above is a very good config file, but it's another way of representing xml. why can't you stick to a simple hash? you don't need the `conf' wrapper. and what are these `elements' that they need to be deeply nested? if they need order, you could use an !omap. --- !omap - one: type - two: type - three: type this will be loaded into ruby as a YAML::Omap object, which acts like an ordered hash. > I'm not a big XML fan, so I'd love to find an alternative, but there are > times where YAML seems a little more awkward than XML. I'm chalking it > up to my lack of YAML experience. i'm not sure what is so akward about even your example: conf: elements: - one: type - two: type - three: type it's free of the angle brackets and quotes which plague your xml equivalent. the white space further enforces the structure. and the dashes reflect a forced ordering. really, i can't imagine such a structure expressed more elegantly. if i'm missing the mark, i'd really appreciate some concrete scenarios which could be fleshed out. _why