The Elegant Chaos Blog

For a long time I’ve been wanting to develop an authoring environment which stores code as some sort of structured database, rather than just a bunch of text files.

Imagine if the program is stored as XML, for example. Perhaps not optimal from an implementation point of view, but it’s a good way to visualise what I’m on about.

Obviously it’s easy to extract the raw source code from the XML if that’s what you want/need to do.

But it’s also possible to extract the actual relationships between program elements, as long as you have some basic knowledge of the object model being used to represent a program.

Suddenly it’s a lot easier to analyse the code. It’s also easier to transform it, so refactoring becomes much simpler.

If you have another language with a compatible representation, you can even automatically translate the code.

Finally, and perhaps best of all, you can add arbitrary meta-data to your code. This could be textual documentation (much more sensible that trying to embed documentation into comments a la JavaDoc), diagrams, optimisation hints, test data for unit tests, whatever.

Anyway, what triggered this particular post was that I came across a reference to an article on the Dylan list, which touches on some of these ideas.


March 23, 2005

In case anyone’s been wondering, here’s what I’ve been working on recently.

A couple of weeks ago I spent Sunday and Monday in a freezing garage in Bath, playing with some prototype slabs (my role mostly consisted of watching other people do stuff, throwing in the occasional suggestion, and getting really cold).

I’ve not been writing anything that interfaces directly with the hardware, but it’s still a really nice change to be working on something that has a physical side to it.


March 23, 2005

I’ve been having fun over the last couple of days playing with a nice combination of SOAP, Applescript, Amazon, Drupal and iTunes.

The result of this unholy alliance is my Now Playing script, which is yet another of those publish-what-iTunes-is-doing-as-if-anyone-cared tools.

At the moment I’ve got an applescript with an idle loop that gets the current track info from iTunes, looks it up on amazon to get a picture, then writes the information out to a small html file.

I’ve then got a bit of PHP code in a custom Drupal block which reads in the html.

At some point it would be nice to merge these into one script, but I think that there might be issues with a perl script on the server talking to an application running logged in as another user (time for a bit more experimentation).

I’m really impressed at the ease with which one can make SOAP requests from Applescript. This stuff has apparently been around since 2001, but I’ve been so wrapped up with Championship Manager that I had no idea.

Thanks to Tim Jarrett, for some scripts which helped set me off in the right direction.

As it happens, his Amazon Handler script seems to be a bit out of date now, so after a lot of head scratching, I figured out how to do things using the latest Amazon SOAP api.

By way of a thank you, here’s some example code. I haven’t generalised things as much as Tim did, so this function is for a very specific job (look up a track and return urls for the amazon page and an image), but it should give you some idea:

on amazonLookup(trackName, bandName)
		set soapParameters to ¬
			 { ¬
				|SubscriptionId|:"1HT82XR9S43B5V8YDQ02", ¬
				|SearchIndex|:"Music", ¬
				|Title|:trackName, ¬
				|Artist|:bandName, ¬
				|ResponseGroup|:"Small,Images" ¬

		using terms from application ""
			tell application ""
				set soapResult to call soap ¬
					{ ¬
						method name: "ItemSearch", ¬
						method namespace uri: "", ¬
						parameters: soapParameters, ¬
						SOAPAction: "" ¬
			end tell
		end using terms from
		set soapOutput to |items| of soapResult
		set itemList to |item| of soapOutput
		repeat with i in itemList
				set a to the itemattributes of i
				if the productgroup of a is "Music" then
					if the artist of a is bandName then
						set imageURL to the |url| of the smallimage of i
						set trackURL to the detailpageurl of i
						return {ok:true, track:trackURL, image:imageURL}
					end if
				end if
			end try
		end repeat
	end try
	return {ok:false}
end amazonLookup

It took me a long time to figure out exactly what parameters I was supposed to be supplying in the SOAP call (the Apple documentation is a bit sketchy), but once I did, it worked like a dream, and it opens up all sorts of interesting possibilities.

What you get back from the call soap call is a compound record which follows the same structure as the XML SOAP reply. From there it is easy enough to extract the information that you’re after.

As I mentioned, this code just gives a very specific example of one call to Amazon to do one thing. There’s a lot more you can do, and the Amazon documentation seems quite extensive.

Have fun…


March 17, 2005

I’m involved in the early planning stage of a couple of projects which might both describe their aims as “to create the next Hypercard”.

This has been an ambition of mine for the last ten years at least, but unfortunately it’s an ambition shared by an awful lot of other people, and so it has become a bit of a hackneyed phrase. Of course, what we definitely don’t want to do is create a Hypercard rip off. There are already some around, they are probably great, and I wish them all well.

What we want to do is to distill the essence of Hypercard - what it was about it which was so fantastic at the time - and apply those same principles to the environment we find ourselves in today.

One thing I’m surprised about is that I couldn’t find a concise description anywhere on the web of what exactly it was that made Hypercard great. As a result, here’s my first attempt: [What Made Hypercard Great?]. I’d be very interested to hear people’s comments.


March 17, 2005

Whatever I do, my Technorati Profile link seems to be producing errors. Not quite sure why.

I blame Kevin Marks (completely arbitrarily you understand). Hopefully he’ll read this post and fix it for me ;)

Update: I’ve deleted all the claims and started again… the JavaScript error was down to Drupal helpfully inserting a <br> tag in the middle of the Technorati script tag.