Application configuration files [closed]
YAML, for the simple reason that it makes for very readable configuration files compared to XML.
XML:
<user id="babooey" on="cpu1"> <firstname>Bob</firstname> <lastname>Abooey</lastname> <department>adv</department> <cell>555-1212</cell> <address password="xxxx">ahunter@example1.com</address> <address password="xxxx">babooey@example2.com</address></user>
YAML:
babooey: computer : cpu1 firstname: Bob lastname: Abooey cell: 555-1212 addresses: - address: babooey@example1.com password: xxxx - address: babooey@example2.com password: xxxx
The examples were taken from this page: http://www.kuro5hin.org/story/2004/10/29/14225/062
First: This is a really big debate issue, not a quick Q+A.
My favourite right now is to simply include Lua, because
- I can permit things like width=height*(1+1/3)
- I can make custom functions available
- I can forbid anything else. (impossible in, for instance, Python (including pickles.))
- I'll probably want a scripting language somewhere else in the project anyway.
Another option, if there's a lot of data is to use sqlite3, because they're right to claim
- Small.
- Fast.
- Reliable.
Choose any three.
To which I would like to add:
- backups are a snap. (just copy the db file.)
- easier to switch to another db, ODBC, whatever. (than it is from fugly-file)
But again, this is a bigger issue. A "big" answer to this probably involves some kind of feature matrix or list of situations like:
Amount of data, or short runtime
- For large amounts of data, you might want efficient storage, like a db.
- For short runs (often), you might want something that you don't need to do a lot of parsing for, consider something that can be mmap:ed in directly.
What does the configuration relate to?
- Host:
- I like YAML in /etc. Is that reimplemented in windows?
- User:
- Do you permit users to edit config with text editor?
- Should it be centrally manageable? Registry / gconf / remote db?
- May the user have several different profiles?
- Project:
- File(s) in project directory? (Version control usually follows this model...)
Complexity
- Are there only a few flat values? Consider YAML.
- Is the data nested, or dependent in some way? (This is where it gets interesting.)
- Might it be a desirable feature to permit some form of scripting?
- Templates can be viewed as a kind of configuration files..
XML XML XML XML. We're talking config files here. There is no "angle bracket tax" if you're not serializing objects in a performance-intense situation.
Config files must be human readable and human understandable, in addition to machine readable. XML is a good compromise between the two.
If your shop has people that are afraid of that new-fangled XML technology, I feel bad for you.