<p>OK, so I don't want to start a holy-war here, but we're in the process of trying to consolidate the way we handle our application configuration files and we're struggling to make a decision on the best approach to take. At the moment, every application we distribute is using it's own ad-hoc configuration files, whether it's property files (ini style), XML or JSON (internal use only at the moment!).</p>

<p>Most of our code is Java at the moment, so we've been looking at <a href="http://commons.apache.org/configuration/" rel="noreferrer">Apache Commons Config</a>, but we've found it to be quite verbose. We've also looked at <a href="http://xmlbeans.apache.org/" rel="noreferrer">XMLBeans</a>, but it seems like a lot of faffing around. I also feel as though I'm being pushed towards XML as a format, but my clients and colleagues are apprehensive about trying something else. I can understand it from the client's perspective, everybody's heard of XML, but at the end of the day, shouldn't be using the right tool for the job?</p>

<p>What formats and libraries are people using in production systems these days, is anyone else trying to avoid the <a href="http://www.codinghorror.com/blog/archives/001114.html" rel="noreferrer">angle bracket tax</a>?</p>

<p><strong><em>Edit:</strong> really needs to be a cross platform solution: Linux, Windows, Solaris etc. and the choice of library used to interface with configuration files is just as important as the choice of format.</em></p>

[{'answer_id': 12147, 'author': 'epatel', 'author_id': 842, 'author_profile': 'https://Stackoverflow.com/users/842', 'pm_score': -1, 'selected': False, 'text': "<p>What platform are you working on? I'd recommend trying to use the preferred/common method for it.</p>\n\n<ol>\n<li>MacOSX - plists</li>\n<li>Win32 - Registry (or are there a new one here, long since I developed on it)</li>\n<li>Linux/Unix - ~/.apprc (name-value perhaps)</li>\n</ol>\n"}, {'answer_id': 12169, 'author': 'rjzii', 'author_id': 1185, 'author_profile': 'https://Stackoverflow.com/users/1185', 'pm_score': 0, 'selected': False, 'text': '<p>As far as I know, the Windows registry is no longer the preferred way of storing configuration if you are using .NET - most applications now make use of System.Configuration [1, 2]. Since this is also XML based it seems to be that everything is moving in the direction of using XML for configuration.</p>\n\n<p>If you want to stay cross-platform I would say that using some sort of a text file would be the best route to go. As for the formatting of said file, you might want to take into account if a human is going to be manipulating it or not. XML seems to be a bit more friendly to manual manipulation than INI files due to the visible structure of the file.</p>\n\n<p>As for the angle bracket tax - I don\'t worry about it too often as the XML libraries take care of abstracting it. The only time it might be a consideration is if you have very little storage space to work with and every byte counts.</p>\n\n<p>[1] System.Configuration Namespace - <a href="http://msdn.microsoft.com/en-us/library/system.configuration.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.configuration.aspx</a></p>\n\n<p>[2] Using Application Configuration Files in .NET - <a href="http://www.developer.com/net/net/article.php/3396111" rel="nofollow noreferrer">http://www.developer.com/net/net/article.php/3396111</a></p>\n'}, {'answer_id': 12184, 'author': 'Kev', 'author_id': 419, 'author_profile': 'https://Stackoverflow.com/users/419', 'pm_score': 3, 'selected': False, 'text': '<p>Without starting a new holy war, the sentiments of the \'angle bracket tax\' post is one area where I <em>majorly disagree</em> with Jeff. There\'s nothing wrong with XML, it\'s reasonably human readable (as much as YAML or JSON or INI files are) but remember its intent is to be read by machines. Most language/framework combos come with an XML parser of some sort for free which makes XML a pretty good choice. </p>\n\n<p>Also, if you\'re using a good IDE like Visual Studio, and if the XML comes with a schema, you can give the schema to VS and magically you get intellisense (you can get one for NHibernate for example).</p>\n\n<p>Ulimately you need to think about how often you\'re going to be touching these files once in production, probably not that often.</p>\n\n<p>This still says it all for me about XML and why it\'s still a valid choice for config files (from <a href="http://www.tbray.org/ongoing/When/200x/2006/12/21/JSON" rel="noreferrer">Tim Bray</a>):</p>\n\n<p><em>"If you want to provide general-purpose data that the receiver might want to do unforeseen weird and crazy things with, or if you want to be really paranoid and picky about i18n, or if what you’re sending is more like a document than a struct, or if the order of the data matters, or if the data is potentially long-lived (as in, more than seconds) XML is the way to go. \nIt also seems to me that the combination of XML and XPath hits a sweet spot for data formats that need to be extensible; that is to say, it’s pretty easy to write XML-processing code that won’t fail in the presence of changes to the message format that don’t touch the piece you care about."</em></p>\n'}, {'answer_id': 12192, 'author': 'dlinsin', 'author_id': 198, 'author_profile': 'https://Stackoverflow.com/users/198', 'pm_score': 0, 'selected': False, 'text': '<p>We are using properties files, simply because Java supports them natively. A couple of months ago I saw that SpringSource Application Platform uses JSON to configure their server and it looks very interesting. I <a href="http://dlinsin.blogspot.com/2008/07/configuration-notations.html" rel="nofollow noreferrer">compared various configuration notations</a> and came to the conclusion that XML seems to be the best fit at the moment. It has nice tools support and is rather platform independent.</p>\n'}, {'answer_id': 12194, 'author': 'Clint Davis', 'author_id': 1340, 'author_profile': 'https://Stackoverflow.com/users/1340', 'pm_score': 2, 'selected': False, 'text': '<p>We are using ini style config files. We use the <a href="http://nini.sourceforge.net/" rel="nofollow noreferrer" title="Nini">Nini</a> library to manage them. Nini makes it very easy to use. Nini was orignally for .NET but it has been ported to other platforms using Mono.</p>\n'}, {'answer_id': 12229, 'author': 'Herms', 'author_id': 1409, 'author_profile': 'https://Stackoverflow.com/users/1409', 'pm_score': 0, 'selected': False, 'text': '<p>Re: epatel\'s comment</p>\n\n<p>I think the original question was asking about application configuration that an admin would be doing, not just storing user preferences.  The suggestions you gave seem more for user prefs than application config, and aren\'t usually something that the user would ever deal with directly (the app should provide the configuration options in the UI, and then update the files).  I really hope you\'d never make the user have to view/edit the Registry. :)</p>\n\n<p>As for the actual question, I\'d say XML is probably OK, as plenty of people will be used to using that for configuration.  As long as you organize the configuration values in an easy to use manner then the "angle bracket tax" shouldn\'t be too bad.</p>\n'}, {'answer_id': 12256, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 5, 'selected': True, 'text': '<p>XML XML XML XML.  We\'re talking <em>config files here</em>.  There is no "angle bracket tax" if you\'re not serializing objects in a performance-intense situation.  </p>\n\n<p>Config files must be human readable and human understandable, in addition to machine readable.  XML is a good compromise between the two.</p>\n\n<p>If your shop has people that are afraid of that new-fangled XML technology, I feel bad for you.  </p>\n'}, {'answer_id': 12264, 'author': 'epatel', 'author_id': 842, 'author_profile': 'https://Stackoverflow.com/users/842', 'pm_score': 1, 'selected': False, 'text': '<p>@Herms</p>\n\n<p>What I really meant was to stick to the recommended way software should store configuration values for any given platform. </p>\n\n<p>What you often get then is also the recommended ways these should/can be modified. Like a configuration menu in a program or a configuration panel in a "system prefs" application (for system services softwares ie). Not letting the end users modify them directly via RegEdit or NotePad...</p>\n\n<p>Why?</p>\n\n<ol>\n<li>The end users (=customers) are used to their platforms</li>\n<li>System for backups can better save "safe setups" etc</li>\n</ol>\n\n<p>@ninesided</p>\n\n<p>About " <em>choice of library</em> ", try to link in (static link) any selected library to lower the risk of getting into a version-conflict-war on end users machines.</p>\n'}, {'answer_id': 12277, 'author': 'engtech', 'author_id': 175, 'author_profile': 'https://Stackoverflow.com/users/175', 'pm_score': 5, 'selected': False, 'text': '<p>YAML, for the simple reason that it makes for very readable configuration files compared to XML.</p>\n\n<p>XML:</p>\n\n<pre><code>&lt;user id="babooey" on="cpu1"&gt;\n    &lt;firstname&gt;Bob&lt;/firstname&gt;\n    &lt;lastname&gt;Abooey&lt;/lastname&gt;\n    &lt;department&gt;adv&lt;/department&gt;\n    &lt;cell&gt;555-1212&lt;/cell&gt;\n    &lt;address password="xxxx"&gt;ahunter@example1.com&lt;/address&gt;\n    &lt;address password="xxxx"&gt;babooey@example2.com&lt;/address&gt;\n&lt;/user&gt;\n</code></pre>\n\n<p>YAML:</p>\n\n<pre><code>    babooey:\n        computer : cpu1\n        firstname: Bob\n        lastname: Abooey\n        cell: 555-1212\n        addresses:\n            - address: babooey@example1.com\n              password: xxxx\n            - address: babooey@example2.com\n              password: xxxx\n</code></pre>\n\n<p>The examples were taken from this page: <a href="http://www.kuro5hin.org/story/2004/10/29/14225/062" rel="noreferrer">http://www.kuro5hin.org/story/2004/10/29/14225/062</a></p>\n'}, {'answer_id': 12287, 'author': 'Lars Mæhlum', 'author_id': 960, 'author_profile': 'https://Stackoverflow.com/users/960', 'pm_score': 2, 'selected': False, 'text': "<p>XML, JSON, INI.<br>\nThey all have their strengths and weaknesses.<br>\nIn an application context, I feel that the abstraction layer is the important thing.<br>\nIf you can choose a way to structure the data that is a good middle ground between human readability and how you want to access/abstract the data in code, you're golden.  </p>\n\n<p>We mostly use XML where I work, and I cant really believe that a configuration file loaded into a cache as objects when first read or after it has been written to, and then abstracted away from the rest of the program, really is that much of a hit on neither CPU nor disk space.<br>\nAnd it is pretty readable too, as long as you structure the file right.</p>\n\n<p>And all languages on all platforms supports XML through some pretty common libraries.</p>\n"}, {'answer_id': 12351, 'author': 'Anders Eurenius', 'author_id': 1421, 'author_profile': 'https://Stackoverflow.com/users/1421', 'pm_score': 4, 'selected': False, 'text': '<p>First: This is a really big debate issue, not a quick Q+A.</p>\n\n<p>My favourite right now is to simply include <a href="http://www.lua.org" rel="noreferrer">Lua</a>, because</p>\n\n<ul>\n<li>I can permit things like width=height*(1+1/3)</li>\n<li>I can make custom functions available</li>\n<li>I can forbid anything else. (impossible in, for instance, Python (including pickles.))</li>\n<li>I\'ll probably want a scripting language somewhere else in the project anyway.</li>\n</ul>\n\n<p>Another option, if there\'s a lot of data is to use <a href="http://www.sqlite.org/" rel="noreferrer">sqlite3</a>, because they\'re right to claim</p>\n\n<ul>\n<li>Small.</li>\n<li>Fast.</li>\n<li>Reliable.</li>\n</ul>\n\n<p><em>Choose any three.</em></p>\n\n<p>To which I would like to add:</p>\n\n<ul>\n<li>backups are a snap. (just copy the db file.)</li>\n<li>easier to switch to another db, ODBC, whatever. (than it is from fugly-file)</li>\n</ul>\n\n<p>But again, this is a bigger issue. A "big" answer to this probably involves some kind of feature matrix or list of situations like:</p>\n\n<h2>Amount of data, or short runtime</h2>\n\n<ul>\n<li>For large amounts of data, you might want efficient storage, like a db.</li>\n<li>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.</li>\n</ul>\n\n<h2>What does the configuration relate to?</h2>\n\n<ul>\n<li>Host:\n\n<ul>\n<li>I like YAML in /etc. Is that reimplemented in windows?</li>\n</ul></li>\n<li>User:\n\n<ul>\n<li>Do you permit users to edit config with text editor?</li>\n<li>Should it be centrally manageable? Registry / gconf / remote db?</li>\n<li>May the user have several different <em>profiles</em>?</li>\n</ul></li>\n<li>Project:\n\n<ul>\n<li>File(s) in project directory? (Version control usually follows this model...)</li>\n</ul></li>\n</ul>\n\n<h2>Complexity</h2>\n\n<ul>\n<li>Are there only a few flat values? Consider YAML.</li>\n<li>Is the data nested, or dependent in some way? (This is where it gets interesting.)</li>\n<li>Might it be a desirable feature to permit some form of scripting?</li>\n<li>Templates can be viewed as a kind of configuration files..</li>\n</ul>\n'}, {'answer_id': 12358, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>Maybe a bit of a tangent here but my opinion is that the config file should be read into a key value dictionary/hash table when the app first starts up and always accessed via this object from then on for speed. Typically the key/value table starts off as string to string but helper functions in the object do things such DateTime GetConfigDate(string key) etc...</p>\n'}, {'answer_id': 12703, 'author': 'Herms', 'author_id': 1409, 'author_profile': 'https://Stackoverflow.com/users/1409', 'pm_score': 3, 'selected': False, 'text': '<p>@Guy</p>\n\n<p>But application config isn\'t always just key/value pairs.  Look at something like the tomcat configuration for what ports it listens on.  Here\'s an example:</p>\n\n<pre><code>    &lt;Connector port="80" maxHttpHeaderSize="8192"\n           maxThreads="150" minSpareThreads="25" maxSpareThreads="75"\n           enableLookups="false" redirectPort="8443" acceptCount="100"\n           connectionTimeout="20000" disableUploadTimeout="true" /&gt;\n\n\n    &lt;Connector port="8009" \n           enableLookups="false" redirectPort="8443" protocol="AJP/1.3" /&gt;\n</code></pre>\n\n<p>You can have any number of connectors.  Define more in the file and more connectors exist.  Don\'t define any more and no more exist.  There\'s no good way (imho) to do that with plain old key/value pairs.</p>\n\n<p>If your app\'s config is simple, then something simple like an INI file that\'s read into a dictionary is probably fine.  But for something more complex like server configuration, an INI file would be a huge pain to maintain, and something more structural like XML or YAML would be better.  It all depends on the problem set.</p>\n'}, {'answer_id': 883847, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>If your configuration file is write-once, read-only-at-bootup, and your data is a bunch of name value pairs, your best choice is the one your developer can get working first. </p>\n\n<p>If your data is a bit more complicated, with nesting etc, you are probably better off with YAML, XML, or SQLite. </p>\n\n<p>If you need nested data and/or the ability to query the configuration data after bootup, use XML or SQLite. Both have pretty good query languages (XPATH and SQL) for structured/nested data. </p>\n\n<p>If your configuration data is highly normalized (e.g. 5th normal form) you are better off with SQLite because SQL is better for dealing with highly normalized data. </p>\n\n<p>If you are planning to write to the configuration data set during program operation, then you are better off going with SQLite. For example, if you are downloading configuration data from another computer, or if you are basing future program execution decisions on data collected in previous program execution.  SQLite implements a very robust data storage engine that is extremely difficult to corrupt when you have power outages or programs that are hung in an inconsistent state due to errors. Corruptible data leads to high field support costs, and SQLite will do much better than any home-grown solution or even popular libraries around XML or  YAML. </p>\n\n<p><a href="http://www.squidoo.com/sqlitehammer" rel="nofollow noreferrer">Check out my page</a> for more information on SQLite. </p>\n'}, {'answer_id': 13366011, 'author': 'AnthonyAlmighty', 'author_id': 855780, 'author_profile': 'https://Stackoverflow.com/users/855780', 'pm_score': 0, 'selected': False, 'text': "<p>I think the only important thing is to choose a format that you prefer and can navigate quickly. XML and JSON are both fine formats for configs and are widely supported--technical implementation isn't at the crux of the issue, methinks. It's 100% about what makes the task of config files easier for you. </p>\n\n<p>I have started using JSON, because I work quite a bit with it as a data transport format, and the serializers make it easy to load into any development framework. I find JSON easier to read than XML, which makes handling multiple services, each using a config file  that is modified quite frequently, that much easer for me!</p>\n"}]
['https://Stackoverflow.com/questions/12144', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1030/']