YAML Rules the Config File and Data Serialization Universe
Though my recent explorations of Ruby and Ruby on Rails, I've become an acolyte in the church of YAML (YAML Ain't Markup Language). It's leagues simpler (and just better IMHO) than XML when used in the places where XML is most frequently deployed today - in config files and for data serialization.
For example, consider the following YAML config file that's used by Rails to define which databases it connects to:
development:
adapter: mysql
database: rails_development
host: localhost
username: root
password: foobar
test:
adapter: mysql
database: rails_test
host: localhost
username: root
password: foobar
production:
adapter: mysql
database: rails_production
host: localhost
username: root
password: foobar
This is highly human-readable - almost intuitively obvious compared to XML. It's something you can very easily modify via the one true editor, a script, or anything else - but surprise: it's also a data structure (a hash of hashes) that can be accessed with almost zero effort. Observe finding the development database's hostname in Ruby:
require 'yaml'
config = YAML.load(File.open('config.yaml'))
puts config['development']['host']
Easy as pie.
Of course the above is just the tip of the iceberg. If you read through the spec from above, the Ruby YAML docs, or the YAML Ruby Cookbook, you'll find that YAML can represent very complex structures in a fashion that feels better than everything that's come before.
Highly recommended.
August 15th, 02005 at 8:21 am
I love these recommendations for development tools. Keep 'em coming. Thanks.
July 5th, 02006 at 5:55 pm
Makes me think: YAML.ini
March 7th, 02007 at 11:38 am
Just what I was looking for! Thank you.