Tuesday, July 10, 2012

A plea for less (XML) configuration files - Nikita Popov

A plea for less (XML) configuration files - Nikita Popov:
I recently tried using Phing (a PHP build system) to do some simple release automation. Just creating a PEAR package and doing a few string replacements here and there.

The result? After several wasted hours I ended up using Phing only for PEAR packaging and doing everything else in a custom PHP build script.

The reason? Phing uses XML files to configure what it should do during a build. So an excerpt from a build file might look like this:

<?xml version="1.0" encoding="UTF-8"?>
<project name="SomeName" default="package" basedir="..">
<target name="package">
<property file="build/build.properties" />
<propertyprompt propertyName="project.version" promptText="Enter project version" />

<delete dir="${path.results.lib}" />
<mkdir dir="${path.results.lib}" />

<copy todir="${path.results.lib}">
<fileset dir="${path.lib}">
<include name="**/**" />
</fileset>
</copy>

<!-- do more stuff -->
</target>

<!-- more targets -->
</project>


Could you explain me, why you have to do this? Why do you have to specify everything in an XML configuration file? Why can’t you just do the same thing in the programming language you’re using? E.g., why can’t I write this instead:

<?php
function package(Phing $phing) {
include 'properties.php';
$project->version = $phing->prompt('Enter project version');

$phing->deleteDir($path->results->lib);
$phing->createDir($path->results->lib);
$phing->copyDir($path->lib, $path->results->lib);

// do more stuff, like replace version strings with $project->version
}


Don’t you think that this is much nicer? Some reasons why I prefer this over XML configs:


  • It uses an environment you’re already used to. You don’t have to learn how exactly the Phing XML files work. You don’t need to learn where you can use properties and where you can’t. You simply know already.


Truncated by Planet PHP, read more at the original (another 2083 bytes)

DIGITAL JUICE

No comments:

Post a Comment

Thank's!