Difference between revisions of "Configuration Files"

From Code4Lib
Jump to: navigation, search
(General rule: use config files for anything local)
m (Protected "Configuration Files" [edit=autoconfirmed:move=autoconfirmed])
 
(7 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
[[Category:Patterns]]
 
[[Category:Patterns]]
  
L57c9h  <a href="http://jlozcxzsieor.com/">jlozcxzsieor</a>, [url=http://uvccoauvpaso.com/]uvccoauvpaso[/url], [link=http://iwxnerlofoym.com/]iwxnerlofoym[/link], http://ctxuejaszhit.com/
+
=General rule: use config files for anything local=
 +
 
 +
==Specific rule: Use a configuration file format that can represent complex data==
 +
 
 +
That’s right, I’m looking at you, .ini and .properties files.
 +
 
 +
Use something like YAML, or XML, or even straight programming-language code (i.e., a file with a PHP hash or a perl hashref or whatnot) that can actually represent, in a logical way, the complexities of the stuff you need to configure. And then, again, have a singleton class that will read that data and expose it in a useful and safe way.
 +
 
 +
And include a semantics checker if you can manage to write one.  It’ll save everyone a load of trouble.
 +
 
 +
Huge bonus points if your configuration singleton class can read from multiple files, overriding previous (default) definitions with subsequent (local) ones.

Latest revision as of 07:27, 24 April 2009


General rule: use config files for anything local

Specific rule: Use a configuration file format that can represent complex data

That’s right, I’m looking at you, .ini and .properties files.

Use something like YAML, or XML, or even straight programming-language code (i.e., a file with a PHP hash or a perl hashref or whatnot) that can actually represent, in a logical way, the complexities of the stuff you need to configure. And then, again, have a singleton class that will read that data and expose it in a useful and safe way.

And include a semantics checker if you can manage to write one. It’ll save everyone a load of trouble.

Huge bonus points if your configuration singleton class can read from multiple files, overriding previous (default) definitions with subsequent (local) ones.