<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>From Accessibility to Zope &#187; Software Engineering</title>
	<atom:link href="http://blog.mauveweb.co.uk/category/software-engineering/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mauveweb.co.uk</link>
	<description>experiments in contemporary web development</description>
	<lastBuildDate>Fri, 30 Jul 2010 13:09:58 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Do not construct URLs with concatenation</title>
		<link>http://blog.mauveweb.co.uk/2007/04/18/do-not-construct-urls-with-concatenation/</link>
		<comments>http://blog.mauveweb.co.uk/2007/04/18/do-not-construct-urls-with-concatenation/#comments</comments>
		<pubDate>Wed, 18 Apr 2007 14:05:42 +0000</pubDate>
		<dc:creator>mauve</dc:creator>
				<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://blog.mauveweb.co.uk/2007/04/18/do-not-construct-urls-with-concatenation/</guid>
		<description><![CDATA[I'm working on an installation of the Joomla! CMS where none of the links are working correctly. Joomla! is very sloppy with URLs. The uploads directory appears to be called images/stories but a quick grep shows that that exact string is referenced 146 times in the Joomla! installation. That's in the source code, not the [...]]]></description>
			<content:encoded><![CDATA[<p>I'm working on an installation of the Joomla! <acronym title="Content Management System">CMS</acronym> where none of the links are working correctly. Joomla! is very sloppy with URLs. The uploads directory appears to be called <tt>images/stories</tt> but a quick grep shows that that exact string is referenced <strong>146 times</strong> in the Joomla! installation. That's in the source code, not the database.  Most of those times it is being concatenated into strings to make URLs.</p>
<p>I've just spent three hours working out that I have no idea what Joomla or the XHTMLSuite editor the client has chosen to use is doing and that I don't give a damn because whatever they are doing, they are wrong.</p>
<p>The correct way to construct a <acronym title="Uniform Resource Locator">URL</acronym> from a filename is not concatenation. Do not do this. It does not work properly. So to avoid any confusion let me state categorically how URLs are supposed to work.</p>
<p>Relative URLs are the only situation where a web browser tries to interpret the query string of an <acronym title="HyperText Transfer Protocol">HTTP</acronym> request. For this purpose, the URLs <tt>http://hostname/directory</tt> and <tt>http://hostname/directory/</tt> are <strong>not the same</strong>. The latter form is correct. The former works because Apache works out that this is a directory and issues an <acronym title="HyperText Transfer Protocol">HTTP</acronym> redirect to "canonicalise" it. Never hard code a <acronym title="Uniform Resource Locator">URL</acronym> for a "directory" which does not contain a trailing slash. If it isn't hard-coded, make sure that the application appends a trailing slash if none exists.</p>
<p>There are two operations which you then need to define to be able to construct URLs:</p>
<ul>
<li>Given an absolute base <acronym title="Uniform Resource Locator">URL</acronym> A, and an absolute or relative <acronym title="Uniform Resource Locator">URL</acronym> B, compute a new <acronym title="Uniform Resource Locator">URL</acronym> B` which is an absolute representation of B in the context of A.</li>
<li>Given an absolute or relative <acronym title="Uniform Resource Locator">URL</acronym>, append a query-string parameter.</li>
</ul>
<p>The first operation is not concatenation. Learn this.</p>
<p>In notation, let A ~ B = B`</p>
<p>So say you want a <acronym title="Uniform Resource Locator">URL</acronym> for a specific uploaded image. Start with a base <acronym title="Uniform Resource Locator">URL</acronym> for your site.</p>
<p><tt>http://mysite/</tt></p>
<p>We then have a relative url of our image directory from the base url.</p>
<p><tt>images/stories/</tt></p>
<p>Then <tt>http://mysite/</tt> ~ <tt>images/stories/</tt>  = <tt>http://mysite/images/stories/</tt></p>
<p>We have a filename of our image, "Uploaded Image.jpg". First, we need to make that a relative <acronym title="Uniform Resource Locator">URL</acronym>. This requires <acronym title="Uniform Resource Locator">URL</acronym> encoding:</p>
<p><tt>Uploaded%20Image.jpg</tt></p>
<p>Then <tt>http://mysite/images/stories/</tt> ~ <tt>Uploaded%20Image.jpg</tt> = <tt>http://mysite/images/stories/Uploaded%20Image.jpg</tt></p>
<p>At this point we have a working <acronym title="Uniform Resource Locator">URL</acronym>. I know, it looks like all we've done is concatenation, and that's why people appear to make this mistake time and time and time again. But it isn't concatenation. What if our base <acronym title="Uniform Resource Locator">URL</acronym> was <tt>http://mysite/CMS/</tt> and our images <acronym title="Uniform Resource Locator">URL</acronym> was <tt>/uploads/</tt> ? Or what if our images <acronym title="Uniform Resource Locator">URL</acronym> is <tt>http://uploads.mysite/</tt>?</p>
<p>More than that, using this operation doesn't let people go wrong. It discourages them from just wedging a / in there in the hope that it will make their URLs work, and prevents ambiguity about whether a piece of code works in all situations or just the way they've got it configured.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.mauveweb.co.uk/2007/04/18/do-not-construct-urls-with-concatenation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unit Testing</title>
		<link>http://blog.mauveweb.co.uk/2007/04/11/unit-testing/</link>
		<comments>http://blog.mauveweb.co.uk/2007/04/11/unit-testing/#comments</comments>
		<pubDate>Wed, 11 Apr 2007 10:19:40 +0000</pubDate>
		<dc:creator>mauve</dc:creator>
				<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://blog.mauveweb.co.uk/2007/04/11/unit-testing/</guid>
		<description><![CDATA[I am missing a way to write unit tests for web applications. I found a few options online, but they aren't really along the lines of what I'm looking for. I want to be able to describe unit and regression tests with respect to expected or unexpected DOM fragments, make requests, fill and post forms, [...]]]></description>
			<content:encoded><![CDATA[<p>I am missing a way to write unit tests for web applications. I found a few options online, but they aren't really along the lines of what I'm looking for. I want to be able to describe unit and regression tests with respect to expected or unexpected <acronym title="Document Object Model">DOM</acronym> fragments, make requests, fill and post forms, check the results and run the whole test suite automatically as a cron job or before committing. I want the whole test suite to be described in <acronym title="eXtensible Markup Language">XML</acronym> so that writing web-level tests doesn't require programming, and so that it can go into Subversion along with the project code.</p>
<p>I think I will have to write this myself. In fact it's something I've been really wanting for years. But I'm way too busy at the moment to do it.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.mauveweb.co.uk/2007/04/11/unit-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>API Design</title>
		<link>http://blog.mauveweb.co.uk/2006/11/08/api-design/</link>
		<comments>http://blog.mauveweb.co.uk/2006/11/08/api-design/#comments</comments>
		<pubDate>Wed, 08 Nov 2006 13:21:22 +0000</pubDate>
		<dc:creator>mauve</dc:creator>
				<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://blog.mauveweb.co.uk/2006/11/08/api-design/</guid>
		<description><![CDATA[My discussion about easy scripting of web apps is part of the subject of API design, which I do find very interesting. API choice is subjective, but is it that subjective? There should be examples of APIs everyone can point to and say "That is how/how not to do it".
Obviously, I'm a fan of object-oriented [...]]]></description>
			<content:encoded><![CDATA[<p>My discussion about easy scripting of web apps is part of the subject of <acronym title="	Application Programming Interface">API</acronym> design, which I do find very interesting. <acronym title="	Application Programming Interface">API</acronym> choice is subjective, but is it <em>that</em> subjective? There should be examples of <acronym title="	Application Programming Interface">APIs</acronym> everyone can point to and say "That is how/how not to do it".</p>
<p>Obviously, I'm a fan of object-oriented <acronym title="	Application Programming Interface">APIs</acronym>, but the ease of use of <acronym title="Object-Oriented">OO</acronym> <acronym title="	Application Programming Interface">APIs</acronym> differs greatly.</p>
<p>Python's standard <acronym title="	Application Programming Interface">API</acronym> is too flat. The modules are self-contained rather than having dependencies on one another. This means most functions will tend to return a primitive rather than a more suitable datatype. There is no consistency in naming, but that's not too bad because of the interactive interpreter and help.</p>
<p>Java's <acronym title="	Application Programming Interface">API</acronym> is too nested. It is totally interdependent, but its power usually comes from composition of the objects rather than subclassing, so some of the packages get extremely complex. It is entirely based on design patterns and has a consistent naming policy which they only break occassionally (*cough* <code><a href="http://www.google.com/search?q=allinurl%3ASystem+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">System</span></a>.<span style="color: #006600;">currentTimeMillis</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></code> *cough*). I think I prefer this to any other <acronym title="	Application Programming Interface">API</acronym> I've used, despite areas of high complexity and still not having found a truly succinct way of using <acronym title="Abstract Windowing Toolkit">AWT</acronym> and Swing (perhaps I will try a <acronym title="XML User Interface Language">XUL</acronym> implementation next time).</p>
<p>The worst <acronym title="	Application Programming Interface">API</acronym> I've ever looked at is <a href="http://xmlsoft.org/html/">libxml2</a>, minor faffing with which is required to get <acronym title="eXtensible Stylesheet Language Transformations">XSLT</acronym> up and running in Python. It's so bad it gives me a headache just looking at the <acronym title="	Application Programming Interface">API</acronym> documentation! Attempting to do anything with <acronym title="eXtensible Markup Language">XML</acronym> without <acronym title="Object-Oriented Programming">OOP</acronym> is just a horrific thing to envisage and for this alone, libxml is contemptible.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.mauveweb.co.uk/2006/11/08/api-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
