Config file standards?

Started by
7 comments, last by swiftcoder 15 years, 9 months ago
Hey there, I would like to know if there are any kind of convention or standards or something regarding to how to make config files. For example, how should I make a config file for a program? An ini file? A text file with fields like "Something=somesetting"? A minimalistic file with all the settings one after another separated by the bit 0? Is there any convention to this? Cause I am kind of perfectionist, I'm not content with things working, and I'm not keen on reinventing the well either. So, I was wondering if there is any way that has proven to be easy to use, fast, and produce cool code. Thanks
Advertisement
.net uses XML
oh right, I forgot. I'm talking about a cross platform proggie, so it has to be a file :) thanks
You might want to check out YAML and JSON.
XML will come closest to anything standardized.

Note that XML compliance has two aspects: well-formed and valid. First means only that tags match, attributes are properly formatted and the rest is written in accordance with encoding.

Valid XML however requires definition of a schema and all of accompanying information. Things get a bit trickier since most XML parsers can barely handle well-formed documents. The "Big Iron" libraries with full validation tend to offer fairly complete support, but even with those I've had problems with character encodings.

One problem you may find tedious with valid XML is that parsing may fail for obscure reasons. Another important note is that libraries to handle valid XML are huge. Things like minimalistic XML parsers simply do not care about compliance, or choose not be compliant for sake of simplicity.

From what I've seen in recent thread here, files produced by boost's XML serialization are valid XML, although I won't guarantee it (I never checked in detail).
hmmm thanks, but i was looking for something that doesn't require aditional libraries.. maybe I'll just go with the typical SomeOption=SomeSetting, one option per line :/
Quote:Original post by gtype
hmmm thanks, but i was looking for something that doesn't require aditional libraries..


In that case, there is nothing. C++ offers no support for configuration files or anything like that. That is, of course, assuming you're using C++. Other languages have INI, XML, or JSON parsers built in.

yes, i'm using c++. thanks for the answer :)
Quote:Original post by gtype
hmmm thanks, but i was looking for something that doesn't require aditional libraries.
A simple key=value setup will work fine for most cases, but you do have to write the parser yourself :)

I would highly suggest you checkout JSON, as it is very lightweight, and there are quite a number of small C++ libraries to parse it.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

This topic is closed to new replies.

Advertisement