Your browser may have trouble rendering this page. See supported browsers for more information.

This page shows the source for this entry, with WebCore formatting language tags and attributes highlighted.

Title

Encodo’s configuration library for Quino: part I

Description

In this article, I'll continue the discussion about configuration improvements mentioned in the <a href="{app}view_article.php?id=3128">release notes for Quino 2.0-beta1</a>. With beta2 development underway, I thought I'd share some more of the thought process behind the forthcoming changes. <h>Software Libraries</h> <pullquote align="right" width="200px">what sort of patterns integrate and customize the functionality of libraries in an application?</pullquote>An application comprises multiple tasks, only some of which are part of that application's actual domain. For those parts not in the application domain, software developers use libraries. A library captures a pattern or a particular way of doing something, making it available through an abstraction. These simplify and smooth away detail irrelevant to the application. A runtime and its standard <i>libraries</i> provide many such abstractions: for reading/writing files, connecting to networks and so on. Third-party libraries provide others, like logging, <abbr title="Inversion of Control">IOC</abbr>, task-scheduling and more. Because Encodo's been writing software for a long time, we have a lot of patterns that we've come up with for our applications. These libraries are split into two main groups: <ul> <b>Encodo.*</b>: extensions to the .NET framework or third-party libraries that don't depend on Quino metadata. <b>Quino.*</b>: extensions to the .NET framework, third-party libraries or Encodo libraries that depend on Quino metadata. </ul> A sort of "meta" library that lies on top of all of this is configuration and startup of applications that use these libraries. That is, what sort of patterns integrate and customize the functionality of libraries in an application? <h>Balancing <abbr title="Keep It Simple, Stupid">K.I.S.S.</abbr> and <abbr title="Don't Repeat Yourself">D.R.Y</abbr></h> Almost nowhere in an application is the balance between K.I.S.S. and D.R.Y. more difficult to maintain than in configuration and startup. <pullquote align="left" width="200px">So if we already know all of that, why does Quino need a new configuration library?</pullquote>As mentioned above, there is a lot of commonality between applications in this area. An application will definitely want to incorporate such common configuration from a library. Updates and improvements to that library will then be applied as for any other. This is a good thing. However, an application will <i>also</i> want to be able to tweak almost any given facet of this shared configuration. That is: just keep the good parts, have those upgraded when they're changed, but apply customization and extend functionality for the application's domain. Easy, right? It is here that a good configuration library will find just the right level of <i>granularity</i> for customization. Too coarse? Then an application ends up throwing out too much common configuration in order to customize a small part of it. Too fine? Then the configuration system is too verbose or complex and the application avoids using it. Instead, a configuration system should establish clear patterns---optimally, just one---for how to apply customization. <ul> The builder of the underlying configuration library has to consider the myriad situations that might face a library developer and distill those requirements to a common pattern. The library developer needs to think about which parts an application might want to customize and think about how to expose them. </ul> So if we already know all of that, then why does Quino need a new configuration library? Well... <h>History of Quino's Configuration Library</h> It's really easy to make things over-complicated and muddy. It's really easy to end up growing several different kinds of extension systems over the years. Quino ended up with a generics-heavy API that made declaring new configuration components very wordy. The core of Quino is the metadata definition for an application domain. That part has barely changed at all since we first wrote it lo so many years ago. We declared it to be our core business---the part that we are better than others at---the part we wanted to have under our own control. Our first draft<fn> has held up remarkably well. Many of the other components have undergone quite a bit of flux: changes in requirements and the components themselves as well as new development processes and patterns all contributed to change. Over time, various applications had different needs and made adjustments to a different iteration of the configuration library. We moved from supporting only single-threaded, single-user desktop applications to also supporting multi-user, multi-threaded services and web servers. <pullquote align="right" width="200px">...we were left with an ugly configuration system that no-one wanted to extend or use---so yet another would be invented.</pullquote>For all of these different applications, we naturally wanted to maintain the common configuration where possible---but customizations for new platforms stretched the capabilities of the configuration library. Customization would be made to a new version of that library, but applications that couldn't be upgraded immediately forced backwards-compatibility and thus resulted in several different concurrent ways of configuring a particular facet of an application. In order to keep things in one place, we ended up breaking the interface-separation rule. Dependencies started clumping drastically, but it was OK because nobody was trying to use one thing without the other ten. But it was hard to see what was going on; customization became a black box for all but one or two gurus. On and on it went, until we were left with an ugly configuration system that no-one wanted to extend or use---so yet another would be invented, ad-hoc. And so it went. <h>Principles for Quino 2.0 Configuration</h> With Quino 2.0, we examined the existing system and came up with a list of principles. <ul> <b>Consistency:</b> there should be only be one way of customizing settings and components. When a developer asks how to change something, the answer should always be the same pattern. If not, there better be a damned good reason (see "Configuration vs. Execution" below). <b>Opt-in configuration:</b> No more magic methods or base classes that automatically add components and settings in black boxes. Even if the application has to call one or two more methods, it's better to be declarative than clever(tm). <b>Inversion of Control:</b> Standardize configuration to use an IOC container or service locator wherever possible. Instead of clumping settings in configuration or application objects, create discrete settings and put them in the container. Make dependencies explicit (constructor parameters!) and resolved through the container wherever possible. <b>Configuration vs. Execution:</b> Be very aware of the difference between the "configuration" phase and the "execution" phase. During configuration, the service locator is used in <i>write-only</i> mode; during execution, the service locator is in <i>read-only</i> mode. Code executed during configuration must rely only on explicit dependency-injection via constructor. <b>Common Usage:</b> Establish a pattern for calling configuration methods, from least to most specific. E.g. call Quino's base configuration methods <i>before</i> any application-specific customization. Establish patterns for how to configure a single startup action or how to create settings for a larger component that could be further customized in subsequent phases. </ul> In the next part, we'll take a look at some concrete examples and documentation for the new patterns.<fn> <hr> <ft>To be fair, it wasn't our first attempt at metadata. In one way or another, we'd been defining metadata structures for generic programming for more years than we'd be comfortable divulging. A h/t of course to Opus Software's Atlas libraries---1 and 2---where many of us contributed. Also, I had experience with cross-platform, generic libraries in C++ stretching all the way back to the late 90s as well as the generalized/meta elements of the <a href="http://data.earthli.com/software/webcore/docs/developer/">earthli WebCore</a>. So it was more like the fourth or fifth shot at it, if we're going to be honest---but at least we got it right. :-)</ft> <ft>In particular, I'll add more detail about "Common Usage" for those who might feel I've left them hanging a bit in the last bullet point. Sorry 'bout that. The day is only so long. See you next time...</ft>