views:

256

answers:

3

I'm reviewing a .NET project, and I came across some pretty heavy usage of .ini files for configuration. I would much prefer to use app.config files instead, but before I jump in and make an issue out of this with the devs, I wonder if there are any valid reasons to favor .ini files over app.config?

+1  A: 

Personally I never user .ini /xml config files to anything more than loading all the values into a singleton or something and then use them runtime like this...

That being said i firmly believe that you should look at the kind of data and the use of data. If the data is in the context of the application in terms of settings and comfigurations then i believe that the app.config file is the right place to hold these settings.

If on the other hand the data is concerned about loading projects, images or other resources concerned with the content of the application then i believe the .ini (does anyone use .ini files anymore? I am thinking a .xml file for storing these information). In short: Segment the content of the data being stored according to the domain and the context.

H4mm3rHead
+2  A: 

Well, on average, .INI files are probably more compact and in a way more readable to humans. XML is a bit of a pain to read, and its quite verbose.

However, app.config of course is the standard .NET configuration mechanism that is supported in .NET and has lots of hooks and ways to do things. If you go with .INI files, you're basically "rolling your own all the way". Classic case of "reinventing the wheel".

Then again: is there any chance this is a project that started its life before .NET ? Or a port of an existing pre-.NET Windows app where .INI files were the way to go?

There's nothing inherently wrong with .INI files I think - they're just not really suported in .NET anymore, and you're on your own for extending them, handling them etc. And it certainly is a "stumper" if you ever need to bring outside help on board - hardly any .NET developer will have been exposed to .INI files while the .NET config system is fairly widely known and understood.

marc_s
The project is relatively new, but the .ini files seems to be bad habbit carried over by some of the developers from past projects. And yes, it's a classic case of wheel reinvention. :) I'm not sure I agree with .ini being more human readable. With .config files, VS and intellisense editing is a breeze. And I would like the team to create a nice schema to support the configuration settings. Thanks for your answer.
Jakob Gade
OK, so if it's just a bad habit, I'd try to change that :-) Try to establish why app.config is superior - better support in .NET, ability to write XML-schema enforced section groups etc - and that hopefully will be the kick in the butt certain devs need to finally give up on the more than 10-year old technology and come around to something newer!
marc_s
+1  A: 

Ini files are quite okay in my book. The problem is GetPrivateProfileString() and cousins. Appcompat has turned that into one ugly mutt of an API function. Retrieving a single ini value takes about 50 milliseconds, that's a mountain of time on a modern PC.

But the biggest problem is that you can't control the encoding of the INI file. Windows will always use the system code page to interpret strings. Which is only okay as long as your program doesn't travel far from your desk. If it does, it has a serious risk of producing gibberish when you don't restrict the character set used in your INI file to ASCII.

XML doesn't have this problem, it is well supported by the .NET framework. Whether by using settings or managing your config yourself.

Hans Passant