03 April, 2011

Registry... but why?

Well, not just Leo's article in the title link, but this and this too.

Of course, it's near impossible to find the old articles now, the explanations offered by M$ back in 1995, when the registry was introduced. And even so, the reasons Leo states could have been solved by storing all the registry information in the filesystem. Here goes:

Separation of "machine" settings from "user" settings. This could have been done by storing machine config in a special directory under Windows directory - there are bunch of such directories already, and guess what, there's a windows\config directory even on my system (and it's empty - go figure). User settings could go into \users\%username%\config. Windows is looking for such places all the time anyway.

Support for different settings for different users. See above - \users\%username%\config, would hold all the user specific settings, just like \Documents and Settings\%username%\Application Data\Microsoft\Credentials\ holds some already. And don't tell me that filesystem is not a database - M$ uses it as a database all the time. And if the registry is a database, well, it's among the worst. Not just by mechanism and structure, but also by the amount of junk it carries.

A centralized location for shared software. Windows has a dozen centralized locations for various things - whatever is under \windows is such a location. Just as all fonts are in a same directory, so can other pieces be. \program files\common is one such place, and any registration could be in one of those desktop.ini, thumbs.db or such files that all Windowses love to scatter around our disks.

Roaming support C'mon, even here M$ doesn't put much in registry - a few flags, keys to set if you want to disable roaming and that's it. The actual info is in various places on the server, in security lists etc, not in any machine's registry.

Registry level security "The registry supports the full Windows security model. That means that access to individual settings can be restricted." says Leo - well, if this security model can't control access to user folders, it's no good anyway.

So why invent registry in the first place? What was wrong with the ini files? We all still use them, and the mechanism to read and write them is blazingly fast.

I can only guess. And my guess is that M$ simply wanted to prevent access to these data, period. Remember, that's exactly when they invented installers. And what's the purpose of installers? To register the app. They also invented the "Windows logo", which meant that your app had to comply with a few GUI guidelines and... it had to use the registry, not ini files.

This meant that you couldn't have a monolythic app anymore, which you could just copy from one machine to another - your runtimes would go into one location, app into another, your shared components couldn't just go into a shared directory - all these locations had to be registered somewhere, so the OS would know how to find pieces needed to run it. To do all that, you had to have an installer, and my experience with these installers over the years are that they are a major pain in the ass - so much that can go wrong, it's a separate universe you need to know well, before you build a good installer.

Again, why? I guess there was money in there somewhere. The industry probably pushed M$ to have something that would prevent simple copying of apps from one machine to another, and M$ being what it is, went for a crazy proprietary binary format, with a mumbo-jumbo API (you can't just read or write a value - you have to open it, read or write, close it - one value at a time; there's no automatic record locking). M$ always goes for weird binary formats - just look at all incarnations of Office. Your emails come as plain text, Outlook stores them in some binary repository (losing a bunch of attributes along the way, and losing part of the header). Text documents become binary all of a sudden, when in Word. Even with the latest crop of Office, the XML is strewn with all sorts of M$ specific stuff - rename any .docx to .zip and start looking into the .xml contained therein... that's anything but simple text.

My tentative conclusion (i.e. until I see any proof to the contrary) is that the registry is an unfortunate hybrid between the requirement to make installation anything but simple (to stop the simplest forms of piracy), to have a config storage which can't be touched by users (without having to rely on file system security, which didn't exist in W95 anyway), and to create a revenue stream by selling knowledge, tools etc.

We all know how this worked out. When I started writing this, I googled reason to have registry in windows and guess what, about 90% of hits were for... registry cleaners. And yes, I already have one.

0 back and forths: