Tuesday, June 9, 2009

Registry Or Configuration File - Years Old Dilemma and Solution

Registry or configuration files:

This article is about a very old question what is the best place to keep your application settings registry or configuration files?  In the end I'll also propose a solution that will offer us best of the both worlds.

Registry:

Pros

There are certain features that simply cannot be achieved without registry. For example windows keep file extension to program mapping in the registry. Registry is also used extensively in COM; in which the COM server use registry to locate the server component. In general any class of information that requires traversal across multiple application configuration is suitable to be stored in registry. I would avoid any further discussion because most of the readers do have a clear idea about registry benefits.

Cons

Ever tried moving an office installation to a different location. It will wreak havoc to your windows installation. Office components will start asking you to reinstall application. When you start application from shell. "windows is searching for application" dialog will show up to waste your precious time. If there are application using Office as COM server they will also break. It makes it very difficult to make an application portable.

A crash in windows registry (if you are lucky enough to start windows) can make a lot of programs non-functional.

Ever try to find what extension an application supports. It would take more time digging into registry than if the same information is provided in a .config file.

Configuration files:

Configuration files are opposite of registry so the benefits of registry can be translated into drawbacks of configuration and vice versa.

Pros

configuration files make an application portable. If everything is stored in configuration files you can easily copy or move the application. Make it easier to make configuration changes specific to the application. for example imagine a program configuration listing the files that can be handled by the application or is handled by application. It is much easier to look at the list rather then searching the registry.

Configuration files exposes the application structure and configurable parameters to user. In registry they are hidden here are there; playing hide and seek with you.

Cons

There are some features that are plain impractical with configuration files. For example windows keep file extension to program mapping in registry. It makes the process of looking up the application path fast. If you are looking for information by class for example all the programs that can handle pdf printing. It would be easier to look at a registry key instead of searching thousands of configuration files.

Solution:

As the above paragraphs clearly explain that both approaches have there on merits. Different personals will endorse different approaches or mix of the two. Some time you don't have a choice. For example if you want to register your program to be the handler of .bmp extension you must use registry in windows. OS guys want to have central repository of configuration on the other hand user and application developer like there application to be as self contained as possible.

In order to get best of both worlds both the OS guys and application developer have to work together.

There are two class of information 1st that must be centrally managed (or put in registry) and other that should go in application's local configuration (.config file).

The OS guys should create standard convention to map the config parameters to registy settings. for example:

<div style="text-align: justify;"><supported_extensions></supported_extensions><br /></div><div style="text-align: justify;">&#160;&#160;&#160; <extension registered="true">bmp</extension><br /></div><div style="text-align: justify;"><br /></div>

 The benefit of defining the standard convention is that both application and OS can manipulate the settings according to user's requirement. In fact the application developer should not be bothered with registry; the mapping and synchronization should be handled by OS. In other words developer should only be concerned with config file not registry.

Tools can be provided to synchronize the configuration file and registry. OS can monitor events such as directory movement and remap specific settings to new directory.

User can use launch parameters or command line parameters to specify whether to launch application using local configuration or settings in registry.

If user copy the application to another machine, he can synchronize the settings on target machine or launch the application with local configuration file.

The OS can also help implement features like portable applications by providing features like "Expose the features temporarily" when you right click an application that exposes features to registry. Those features can be mounted to registry temporarily until the user unmount the application or device. OS can also handle a lot of registration automatically by monitoring the config files. Instead of relying on application to manually manipulate registry. For example:

<classid id="abc20940930..." description="etc">

OS can scan the .config file and build the registry keys automatically. User can right click the main directory and click synchronize settings. Upon registry crash OS can scan the file system to build the registry again.

A lot more can be written on the subject but I think the above paragraphs clarify the concepts and provides the foundation to build upon.

No comments:

Post a Comment