XML Configs Suck

written by Geoff Bowers on Friday, 15 August, 2008 @ 01:00 AM

While XML is a great format for structured data, its not ideal for configuring code frameworks. When working with a framework your code is often broken up into smaller segments that are coordinated at run time. All to often this coordination is wired together using XML configuration files. Its this separation of configuration from code that makes XML so sucky. Embedding metadata into the code itself seems like a much more natural way to manage complex configuration.

Imagine there's no code, just metadata captured through the use of cfproperty. In fact, all the metadata you might need to describe exactly how the component should be persisted in the database, its relationship to other components, the behaviour of its form elements when editing, the periodicity for caching its views, and even enough rudimentary information to display information to users.

In the FarCry Core web application framework you might describe a super hero with a few properties. Name and type are enough basic information for the framework to understand how to persist the data model in the database (mySQL, MSSQL, Postgres and Oracle supported) and even provide rudimentary edit handlers.


<!--- ./packages/types/superHero.cfc --->
<cfcomponent name="superhero" extends="farcry.core.packages.types.types" output="false" displayname="Super Hero">
 <cfproperty name="title" type="string" default="" hint="Super hero title." />
 <cfproperty name="secrethideout" type="string" hint="The secret hideout location of the super hero" />
 <cfproperty name="teaser" type="longchar" default="" hint="Mini intro for super hero biography." />
 <cfproperty name="biography" type="longchar" default="" hint="Super hero biography." />
 <cfproperty name="imgHero" type="string" hint="The image of the hero" />
</cfcomponent>




But the fun really starts when you play with the extensive "formtool" library; look out for the attributes with the ft prefix. Just by nominating metadata you can start to generate very rich edit handlers all without a single line of code. Of course if you need to get your hands dirty you can build your handlers from scratch or leverage just parts of the formtool engine as needed.


<cfcomponent ...>
 <cfproperty ftSeq="1" ftFieldset="General Details" name="title" type="string" default="" ftLabel="Title" hint="Super hero title." />
 <cfproperty ftSeq="2" ftFieldset="General Details" name="secrethideout" type="string" ftLabel="Secret Hideout" hint="The secret hideout location of the super hero" />
 <cfproperty ftSeq="3" ftFieldset="General Details" name="teaser" type="longchar" default="" ftLabel="Teaser" hint="Mini intro for super hero biography." />
 <cfproperty ftSeq="4" ftFieldset="General Details" name="biography" type="longchar" default="" ftLabel="Biography" ftType="richtext" hint="Super hero biography." />
 <cfproperty ftSeq="10" ftFieldset="Imagery" name="imgHero" type="string" ftType="image" ftLabel="Hero Image" ftDestination="/superhero/imgHero" ftImageWidth="120" ftImageHeight="120" ftAutoGenerateType="fitInside" hint="The source image to upload" />
</cfcomponent>




FarCry even handles one to many and many to many relationships through metadata. Adding an array type and nominating the objects it can join to updates the model and provides comprehensive library ui tools for editing the relationship.


<cfcomponent ..>
 ...
 <cfproperty ftSeq="12" ftFieldset="Related Content" ftWizardStep="Relationships"
 name="apowers"
 type="array"
 ftLabel="Powers"
 ftJoin="superPower"
 hint="Array of superhuman powers." />
 ...
</cfcomponent>




The metadata kind of tells story right there in the code to both the developer and the framework. It's much more intuitive than trying to capture the same information in a separate XML file. Its just one of the reasons I love working with a framework like FarCry Core.

Comments

Permalink: http://blog.daemon.com.au/go/blog-post/xml-configs-suck

Options:

Size

Colors