Welcome to the 151st Ranked Blog in NZ

You find the most interesting things trawling through the “Incoming Links” section of the WordPress Admin Dashboard. According to this page at halfdone (I’d never heard of them either), Life of Andrew is the 151st in their list of NZ blogs that are “about something”.

I am not entirely clear how they calculate the rankings, but I am happy with 151 – surrounded by other blogs handling the big issues of the day: 150 (MENZ Issues: Promoting a Clearer Understanding of Men’s Experience, example post: “Feminists in denial about how they are failing girls“) and 152 (Web of Evidence: What They Don’t Want You To Know, example post: “Numerous Long Fibers Seen Floating Through The Air In Whangarei, NZ” )

And people say that bloggers are just weird malcontents.

TV Theme Quiz II : The Themes Strike Back

It was bound to happen. People seemed to enjoy the first TV Theme Quiz so I fired up Audacity and created another 30 seconds of familiar ditties. Things were solved pretty quickly last time so I tried to make this one just a smidgeon harder – we will see if I succeeded.

Start TV Theme Quiz II

This quiz works in much the same way as the last one but I have tweaked the Javascript a little. I never thought that anyone would bother reversing the hash used to hide the answers on the first quiz but one of my friends admitted that they had done just that. A little salt should clear that problem right up.

This is the post you should comment on for hints and bragging. I only ask that you refrain from posting the actual answers, at least for the first few days. I think it is better to let people work things out for themselves.

A Better Boost Book

Boost is a excellent resource for C++ programming, but suffers from inconsistent documentation and a daunting array of sub-projects. Trying to make sense of it all is a fairly serious undertaking. I tried to get my head around it by writing my occasional series of boost blog posts, but now I see that somebody has done a much better job.

The Boost C++ Libraries is a free book that clearly explains some of the more generally useful boost libraries, with lots of useful examples. It even covers advanced libraries like ASIO in an approachable way. I highly recommended bookmarking it if you do any C++ programming.

The HTML5 audio tag

I have been mucking around with the audio tag as part of my quest to understand where HTML5 is going. The <video> tag gets all the press but I think there are many more opportunities to use audio in web apps. HTML5 is closing the gap between plugin-based apps (Flash, Silverlight, Java, etc) and sound support is an important part of that goal.

(Those of you who don’t care how it works should go directly to the TV Themes demo puzzle. It works best in Firefox3.6 and the latest version of Safari, although most browsers should function to some degree.)

The audio tag is pretty flexible, able to handle both long form audio (songs and spoken passages – the theme medley on the demo page for example) and short snippets of background audio (alerts, and confirmations – the demo plays one of two short tones when you type an answer. Video game sound effects are another example.) Optionally, the audio tag can provide a user interface for starting and stopping the audio, useful for playing long streams of audio. Different browsers have different ideas about how this should look, but they all function much the same way.

In theory, the audio tag is as easy as embedding an image into HTML:

1
2
3
4
<audio controls>
	<source src="music.mp3">
	You can put HTML here that will be displayed if the browser does not understand the audio tag
</audio>

However, the devil is in the details. There are two problems with the audio tag that complicate matters. The first is that only the very latest browsers support the audio tag at all. This means that if you want to provide audio that everyone can use, you are going to have a fall-back method available. Before the audio tag, people used to use Flash for this purpose and it still works. A number of sites provide simple Flash-based audio players that you can embed – I ended up using the player provided by Google.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<object codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" height="27" width="400" align="middle" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000">
	<param name="_cx" value="10583"><param name="_cy" value="714"><param name="FlashVars" value="">
	<param name="Movie" value="http://www.google.com/reader/ui/3247397568-audio-player.swf?audioUrl=http://full/path/to/music.mp3">
	<param name="Src" value="http://www.google.com/reader/ui/3247397568-audio-player.swf?audioUrl=http://full/path/to/music.mp3">
	<param name="WMode" value="Window"><param name="Play" value="0">
 
	<param name="Loop" value="-1">
	<param name="Quality" value="High">
	<param name="SAlign" value="LT">
	<param name="Menu" value="-1">
	<param name="Base" value="">
	<param name="AllowScriptAccess" value="never">
	<param name="Scale" value="NoScale">
	<param name="DeviceFont" value="0">
	<param name="EmbedMovie" value="0">
 
	<param name="BGColor" value="">
	<param name="SWRemote" value="">
	<param name="MovieData" value="">
	<param name="SeamlessTabbing" value="1">
	<param name="Profile" value="0">
	<param name="ProfileAddress" value="">
	<param name="ProfilePort" value="0">
	<param name="AllowNetworking" value="all">
	<param name="AllowFullScreen" value="false">
 
	<embed type="application/x-shockwave-flash" src="http://www.google.com/reader/ui/3247397568-audio-player.swf?audioUrl=http://full/path/to/music.mp3" allowscriptaccess="never" quality="best" bgcolor="#ffffff" wmode="window" flashvars="playerMode=embedded" pluginspage="http://www.macromedia.com/go/getflashplayer" height="27" width="400" />
</object>

Not exactly elegant, is it? Apart from being uuuuug-ly, the full URI of the sound file must be used (the audio tag can use relative paths). Also, the Flash players are not scriptable in the same way as inbuilt audio tag is, which can make doing tricky stuff like animating other content in response to the audio more difficult.

The second problem with the audio tag is the same codec problem I talked about in a previous rant (The HTML5 Video Tag’s Fatal Flaw) For legal reasons, different browsers play different formats of audio – most notably Firefox will not play mp3s while Safari will not play ogg. There is no single format that will play in all browsers except for uncompressed wavs, which are too fat to be useful except for very short snippets.

To get around this problem the audio tag allows multiple files to be specified. The first file that the browser thinks it can play will be used, but it does mean you have to encode and store multiple versions of each audio file.

1
2
3
4
5
<!-- Only one of these files will be downloaded -->
<audio controls>
	<source src="music.ogg" type="audio/ogg">
	<source src="music.mp3" type="audio/mpeg">
</audio>

The demo page also uses the audio tag to play sound effects in the background, using audio elements that do not have a user interface. For simplicity I used wav files (download from this awesome source of free effects.) Since they have no user interface, Javascript must be used to play them:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<audio id="clicksound" preload="auto">
	<source src="click.wav" type="audio/wav">
</audio>
 
<script type="text/javascript">
function playSound( )
{
	var a = document.getElementById( "clicksound" );
	if ( !a ) return;
	if ( !a.play ) return; // will exit if the browser does not understand the audio tag
 
	a.play();
}
</script>

It is all pretty simple but as always there are problems. I did not find a good way of replicating this using Flash, so browsers that do not understand the audio tag do not play these background noises. Also, Google Chrome (which has otherwise excellent support) contains a weird bug that prevents it playing the first couple of seconds of an audio file, making it useless for short sounds. Apparently Firefox3.5 had the same problem, but it works perfectly in 3.6.

I created the demo to see if the audio tag could replicate the functionality of Flash-based applications for both long-form audio and background sound effects. It does seem to be possible provided you are targeting a modern browser and are prepared to work around certain annoyances. Hopefully the next few years will see an improvement in support for audio, I can see many uses for it especially if the iPad (which does not support Flash) takes off.

Using Exceptions in C++

C++ is big – it has been said that any given programmer only ever uses about 40% of the language’s features. The trouble is that it is a different 40% for each person. Exceptions are a great example of this, some people swear by them while many coding standards specifically ban/discourage them (cf: google, mozilla). It is ironic that a feature designed to make code safer is sometimes regarded as being too dangerous to use.

Personally I like exceptions, but even I realise that they have there limitations. This post is an attempt to formalise some guidelines about when exceptions should be used and when they should be avoided beyond the usual language rules. I should mention at this stage that most of my experience is in desktop client/server software. C++ is used in all sorts of places these days, and what works on desktops and beefy servers may not suit the embedded world (for example).

When to Catch

My rule of thumb is “Do not let exceptions escape from a function you didn’t explicitly call yourself“. This includes destructors, callbacks, thread functions, WNDPROCs, and any other miscellaneous way your functions can be entered (it does not include constructors or virtual functions – exceptions are very useful in those). In general, all these things should catch and handle all exceptions.

Your program will die if an exception escapes a thread. If you are lucky your runtime will do something clever and your program will die painlessly but possibly the OS will have to dispatch the process messily. Either way, your users will not be impressed, so you should always wrap thread functions in try{}catch blocks. In the best case you might be able to signal that an operation failed to the main thread, which can restart it if required. In the worst case you can at least log what happened before exiting.

Lots of third part libraries communicate with your code using callbacks that you supply. You should always ensure that any exceptions are caught before returning back into third party code, since you can never be sure if the library does the right thing. C style libraries like LibCURL are right out, they will probably leak handles and memory as the stack is unwound. C++ libraries may (or may not) be better but could do things you do not expect, like swallow the exceptions themselves instead of letting them fall through (boost::iostreams). Also, some libraries actually call you back on a different thread (boost::asio) so the advice in the previous paragraph also applies here.

You should always be prepared to catch any exceptions that are documented by any C++ libraries you use, especially things like boost::filesystem which can throw at any time.

What to Throw

My advice is to create a small hierarchy that is derived from std::runtime_exception unless you are already using a custom exception class. Don’t try to get clever and throw std::string or char*. Design your hierarchy around how the exceptions are to be handled, rather than what can go wrong. For instance, if there are 5 different ways your program throw exceptions, but only 3 different things that can happen in response then you only need 3 types of exceptions.

In my experience, exceptions fall into two categories: recoverable and fatal. Recoverable exceptions will be caught within a layer, or perhaps the next layer up which can then reattempt the operation (or perhaps just log and ignore the problem if the operation was not crucial.) Fatal errors are usually not caught until the outer loop of the program, where they are logged before the program can be shutdown cleanly. In general, the exceptions you expect to recover from should derive from exceptions you expect to be fatal.

I tend to name my exception types based on how they are handled and what circumstance they represent, like so:

1
2
3
4
5
6
7
8
9
10
11
12
13
class UnrecoverableFileReadException : public std::runtime_error
{
	// thrown when a file cannot be read correctly, ie: the file exists but is misformatted
public:
	UnrecoverableFileException( const std::string& msg ):std::runtime_error(msg) {};
};
 
class FileReadException : public UnrecoverableFileReadException
{
public:
	// thrown when a file cannot be read but the user can be prompted to select another file
	TemporaryFileException( const std::string& msg ):UnrecoverableFileReadException(msg) {};
};

When throwing, always construct the exception with a sensible message if only for logging and debugging purposes. Normally this message would not be shown to the user since it will be hard to localise. Add additional members to your exception class if you want to include other information with the exception. Just remember that exceptions must be copyable.

1
2
3
ostringstream oss;
oss << "Could not open file " << filename << " the error was: " << errno;
throw TemporaryFileException( oss.str() );

If you really want to go the whole hog consider using boost::exception which builds upon similar ideas.

When to Throw

Exceptions should never be thrown if everything is running perfectly. Only when something goes wrong should throwing an exception be considered an option. I have seen code that threw exceptions to signal the end of an enumeration or to signal that the results of a query were empty – I consider these examples to be a terrible use of the feature. Remember that an exception is not just an error, but something really outside of normal program flow.

I also tend not to use exceptions for logic errors. If an algorithm can fail then the calling code should be prepared to handle a return code signalling an error. Likewise I would not throw if a database query returned no results – an empty result set is inside the bounds of normal program flow. However, I would consider throwing an exception if the query failed due to the database being unavailable.

The best places to use exceptions are in situations where your program is using resources that are not under your control, including anything to do with IO. Both files and network connections exist outside of your program and can become unavailable at any point due to any number of reasons. In many cases the problems are transient and all your program needs to do is try again in a few minutes – a program that quits each time the DNS, directory server, or external database cannot be reached will not survive for very long in any production environment. Exceptions allow you to back out of an operation without too much trouble and handle the problem in a sensible location.

One problem you might encounter is that is often hard to retrofit exceptions into code that wasn’t designed for them. In this case, my advice about not letting exceptions fall through 3rd party code also applies to legacy code that you own. This is not to say that you cannot use exceptions at all, just that you may have to take steps to keep exception handling within the layers of your application.

Mobile Safari Does Not Support Flash (and Never Will)

Listening to some people, the lack of Flash on the iPhone/iPad is some sort of crime against nature. There are numerous complaints about it online – all bemoaning the inability to play their favourite Flash games or view video. These complaints miss the point entirely – there are two simple reasons why Flash will never be supported in Mobile Safari.

The first reason is simple – Steve Jobs is a jealous God and thou shall have no other Gods besides Him. Apple created the App store so they would control the single way of getting software onto the device, being able to load a flash file from a browser completely circumvents this control. Simple.

Now we have that out of the way, we can move onto the second, more interesting, reason.

Flash would suck on the iPhone.

Lets talk about Flash video first. Most video sites use a custom Flash wrapper to display video in a sub-frame of the browser, with controls to zoom the video to full screen. The sub-frame is usually of a fixed size (640*360, etc) and surrounded by additional HTML (ads, links to other videos, etc). Straight away you should see the problem – the video is already bigger than the iPhones screen. Mobile Safari does an excellent job of resizing web pages, but that is going to leave you with a postage stamp sized video with even smaller controls. Going fullscreen may be a solution, if you can mange to tap the tiny button, but then you are not really using Flash as part of a web page anymore.

Back in the day (about 5 years ago), Flash video was a step above anything else on the web due to its widely deployed and not-too-bad codec. These days Flash is just a none-too-convenient way of displaying standard h264 files which the iPhone can play natively. Most of the big video sites have realized this and just serve the raw file to iPhones instead of trying to wrap it in a custom player, to the benefit of everyone.

(Drifting slightly off-topic for a moment, I imagine the use of Flash as a video player will start to decline even of desktops now that HTML5 is here with its useful <video> tag.)

Now lets talk about Flash games – Tower Defense, Crayon Physics, room escape puzzles, etc. I love them, you love them, everyone loves them. There is just one problem – none of the thousands of existing games would work on the iPhone even if Mobile Safari supported Flash perfectly!

The iPhone doesn’t have a keyboard, so most arcade-type games are right out. Even games that exclusively use the mouse would have problems since tapping your finger on the screen is much, much less precise than using a pointer. In addition, on the iPhone you effectively have multiple pointing devices – how would current Flash apps handle that?

For a quick demo of why sites like newsgrounds will never work on the iPhone, resize your browser window to 480*320 (or 320*480 since that is more usual) and visit your favourite gaming site. Now set your mouse pointer to a big white blob instead of an arrow to simulate tapping with a large figertip. Remember to stop playing after 45 minutes to replicate the battery drain. See how much fun you have.

UIButton.titleLabel is not as useful as it looks

I have been doing some iPhone development lately. Nothing too amazing, just some test apps to get a feel for the system. Now, some people will tell you that Cocoa Touch is an API sent from God and frankly it is pretty good (especially given what passes for UI on other embedded devices), but that doesn’t mean it doesn’t have some annoyances.

Here is something that tripped me up for a while. The UIButton class has a property called titleLabel which (obviously) returns the UILabel that is used to display the text of the button. You can use this property to modify the parameters of the label, like so:

1
2
3
m_addButton.titleLabel.font = [UIFont systemFontOfSize: 7];
m_addButton.titleLabel.textColor = [UIColor blackColor];		 
m_addButton.titleLabel.textAlignment = UITextAlignmentRight;

What you can’t do is this:

1
m_addButton.titleLabel.text = @"Add Stuff";

Although nothing I have found in the documentation says so, the text of the button cannot be set from the titleLabel property. What you have to do is this:

1
[m_addButton setTitle:@"Add Stuff" forState: UIControlStateNormal];

Setting the title this way works, and has the advantage that you can specify different text for different states:

1
2
[m_addButton setTitle:@"Add Stuff" forState: UIControlStateNormal];
[m_addButton setTitle:@"Add Stuff (not now)" forState: UIControlStateDisabled];

This is perhaps not that interesting for text titles, but is an excellent way to control the image the button shows based on whether the button is enabled, highlighted, and/or selected.

The C++ Boost Libraries Part 6 – boost::any

In C++ if you have a variable that you say is of type “Person” (for instance), you can be fairly certain (more or less) that it always actually contains a Person (or perhaps a subclass of Person. If you have a container of Persons, then you know (more or less) that every member is also a Person (or a subclass).

This is all very good, prevents a lot of runtime errors, and generally makes C++ a great language if you care about correctness. But sometimes, very rarely, you actually want to store a whole bunch of messy, unrelated types in a container without trying to ram them into some sort of class hierarchy. Parsers are a good example of this. It is often convenient just to chuck tokens of various types into a data structure for later processing without worrying too much about the specific type (string, int, float, etc).

boost::any is a small class that can hold values from almost any type, designed for just such messy applications. Using boost::any is very simple:

1
2
boost::any a1 = std::string("Moose");
boost::any a2 = 6;

Of course, getting the values back again is a little harder.

1
2
3
4
5
6
7
8
9
try
{
	std::string v1 = boost::any_cast< std::string >(a1); // this works, a1 is a string
	std::string v2 = boost::any_cast< std::string >(a2); // nope, will throw an exception at runtime
}
catch ( const boost::bad_any_cast& e )
{
	// tried to any_cast into something that wouldn't go
}

Of course, you can query a boost::any for the typeid of the stored object. Just don’t do it when Scott Meyers is in the vicinity.

1
2
3
4
5
std::string v;
if ( a1.type() == typeid(std::string) )
{
	v = boost::any_cast< std::string >( a1 ); // this should never throw, since we checked first
}

A single boost::any is perhaps not that useful, but a container of them can store almost anything we want:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
typedef std::vector< boost::any > AnyVector;
AnyVector values;
 
values.push_back( 5 );
values.push_back( std::string("Hello") );
values.push_back( 5.3 );
 
try 
{
	for ( AnyVector::const_iterator p = values.begin();
			p != values.end();
			++p )
	{
		if ( p->type() == typeid(int) )
			cout << "Int = " << any_cast<int>(*p) << endl;
		else if ( p->type() == typeid(std::string) )
			cout << "String = " << any_cast<string>(*p) << endl;
		else 
		{
			cout << "Unhandled type: " << p->type().name() << endl;
		}
	}
} 
catch ( const boost::bad_any_cast &e )
{
	cout << "Bad any_cast<>" << e.what() << endl;
}

Any type that you put into a boost::any must be copy constructable (the any makes a copy, not a reference). You also have to make sure that its destructor doesn’t throw (but of course you do that anyway!)

Although I wouldn’t recommend boost::any for everyday use, it does come into its own when the only alternative is a huge class structure or (even worse) void *s.

Python and The Very Slow Server

I don’t usually do a lot of Python programming, but I always enjoy it when the opportunity arises. Python is in no way a “clean” language, it has all sorts of warts and limitations that mean that it tends to not get used for big projects. Despite this (or maybe because of it), Python remains my go-to language for Getting Small Things Done Quickly. It is impossible to overstate the utility of just being able to start coding a function by bashing away at the python console – nothing else has given me the same sense of instant gratification since I started programming in BASIC back in the 80s.

The other big advantage of Python is the useful utility libraries that come with it as standard. Want to send twenty thousand emails? Just import smtplib. Want to generate code based on data from a spreadsheet? Import csv and away you go. Need a file that is exactly 32Mb is size? No problem. These are real examples from my job where Python has saved me many hours.

The most recent use I have put Python to is a slow server. For various murky and uninteresting reasons I need a rate-limiting HTTP server, one that I can easily control the speed at which it sends data. Enter Python’s very handy BaseHTTPServer module, which allows you to create custom HTTP servers with only a few lines of code by subclassing a request handler. Although the BaseHTTPServer is fairly useless for serving real files, it is perfect for this type of thing since it does all the boring work of parsing headers and returning status codes.

I don’t care about the contents of the data, just its size and how long it takes to serve. Since I will be varying these parameters a lot, I decided to make them part of each request so that each request could take a different amount of time – this means I don’t have to restart the server between each test run. Modifying the code to serve actual file data would be very simple.

I enjoyed writing this server so much that I regret that it didn’t take longer. Now I actually have to use it for its intended purpose, which I can assure you is not going to be as pleasant.

Here is the complete Python source:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# A very simple HTTP server designed to for testing situations where the data returned
# is not important but the rate at which it comes down is. This server can be started
# using the command: python delayserver.py
#
# Once started, it will listen for requests on port 8000
# Requests should be of the form http://<address>:8000/size=<bytes>,duration=<seconds>
# where: <bytes> is the size of the response data
# and    <seconds> is how long you want it to take (at minimum, it may take longer)
#
# Notes:
# * The timing is pretty inaccurate for small byte sizes, this isn't a problem for
#   what I need it for
# * Press ctrl-c to stop serving
 
 
import time
import BaseHTTPServer
 
class MyHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
 
	def do_GET(self):
		request = self.path.strip("/")
		duration = 1
		size = 1024
 
        	validRequest = False
		params = request.split(",")
		for p in params:
                    temp = p.partition("=")
                    if (temp[0] == "size"):
                        size = int(temp[2])
                        validRequest = True
                    elif (temp[0] == "duration"):
                        duration = int(temp[2])
                        validRequest = True
 
                if (validRequest == False):
                   self.send_error(404)
                   return
 
                self.send_response( 200 )
                self.send_header( "Content-Length", str(size) )
                self.send_header( "Pragma", "no-cache" )
                self.end_headers()
                self.slowWrite( self.wfile, size, duration )
 
 
        def slowWrite(self, output, size, duration):
                bytesWritten = 0
                startTime = time.time()
                while ( bytesWritten < size ):
                        now = time.time()
                        if (duration != 0):
                                desiredBytes = ( (now - startTime) / duration ) * size
                        else:
                                desiredBytes = size
                        desiredBytes = min( size, desiredBytes )
                        if (desiredBytes < bytesWritten ):
                                time.sleep(0.2)
                        else:
                                while (bytesWritten < desiredBytes):
                                        output.write('A')
                                        bytesWritten = bytesWritten + 1
                                output.flush()
                now = time.time()
                self.log_message( "Request took %f seconds",   now - startTime  )	
 
if __name__ == "__main__":
    http = BaseHTTPServer.HTTPServer( ('', 8000), MyHTTPRequestHandler )
    print "Listening on 8000 - press ctrl-c to stop"
    http.serve_forever()

I should point out that I am by no means an expert at Python, so take this code with a pinch of salt.

Catan – The First Island

Catan ScreenshotI love the Settlers of Catan board game, so when an iPod version appeared in the App Store for $6.49 I grabbed it straight away. Dubbed “Catan – The First Island“, the app includes everything in the core game, I assume more games based on the Catan expansions are on the way.

The app plays a pretty good game, the interface is fairly straight forward and trading between players is handled well. Some rule variants are supported, like starting with a city instead of a settlement or different point targets. There are even different ways of distributing the resources for wusses who can’t take random chance. The computer players put up a fair challenge, and you can play hot-seat multiplayer but there is no internet play – an obvious omission.

Unfortunately, Catan also has some fairly annoying flaws. Firstly, the game is buggy. On both my first two games the computer player refused to finish its turn, leaving aborting the game the only option. The other 3 games I have had have worked smoothly so I still don’t know what I did to trigger that bug. Loading a saved game also sets some of the options back to the default, which is a pain but not game breaking.

Speaking of saved games, Catan does not automatically save your progress when you dismiss the app to go back to the iPod main menu. When you re-enter Catan it pops you back at the title screen with no way to resume unless you manually saved the game, something you can only do during your turn. This is intensely annoying, not to mention against Apple’s App guidelines and I hope the fix this if nothing else in an update.

The graphics are just OK, they get the job done without being very attractive and the board animation looks terrible. The whole package seems just a little unpolished – it works but needs just a little more attention to detail. The only thing that really saves Catan as an App is the mechanics of the game itself, which still shine. Perhaps after an update or two “Catan – The First Island” will reach its potential, but right now it is only for die-hard Catan fans.

A disappointment, only recommended if you like this sort of thing.

How to change the dictionary in MacOSX

I love MacOSX, and one of the best features is the almost ubiquitous built-in dictionary. So it is surprising that I after 3 years I have only just now discovered how to switch the dictionary from the default American English to British spellings. For some reason this is not part of the normal System Preferences pane, nor does setting your region or system language have any effect on spelling. I knew there had to be a way, but could never find the trick until today.

In case anyone else is having the same problem, here is what you have to do:

  1. Open an application that supports the in-built dictionary (pretty much anything except for Firefox). If in doubt use TextEdit.
  2. Right click on a text input area and select Spelling and Grammar -> Show Spelling and Grammar from the menu. Alternatively, the same menu option is available from the Edit menu.
  3. Select the dictionary you want from panel that pops up. Although the panel looks like part of the application you are using changes to the settings here apply across the entire OS.
  4. Enjoy the sensation of spelling words with lots of silent letters just like Queen Elizabeth II and God.

spelling

Space Ace

Remember Space Ace? The massive machine at the back of the greasy arcade you used to frequent? The one that played a cartoon that you had to react to? The one that cost twice as much as any other game? Of course you do. Well now it is back, and it’s just as bad as it was back then.

Space Ace

Space Ace (like its older brother, Dragon’s Lair) was/is on the very edge of the graphics/gameplay scale. The graphics were amazing, consisting of several minutes of action packed hand-drawn animation. But all it was really doing was playing video clips straight from a laser disk which meant that interaction was limited. Every few seconds something on the screen would flash, which was your cue to move the joystick in that direction. React too late and the hero would die in some amusing way. There was nothing quite like it.

Space Ace has just appeared in the iTunes store, and I felt oddly compelled to shell out the $6.50 asking price and suffer through the 280Mb(!) download. The animation is just as I remember it, unfortunately so is the gameplay. It is basically Guitar Hero, but “controlling” the beats of action on screen rather than beats in a musical score. This is not in itself a terrible idea, but there is only so much video you can fit on a laser disk circa 1982 so the plot is very short and once you have learnt the patterns the game is very easy. The onscreen joystick works OK, but is quite picky so you have to be exact with your fingers.

Space Ace

Despite these limitations, Space Ace is in its heart an imaginative and silly game. I find myself enjoying revisiting it even though I will probably finish it in the next few days.

View Space Ace attract sequence on Youtube.

WordPress Upgrade Time

I have just upgraded to the latest version of WordPress. Usually this is a simple procedure, but this time something went wrong – attempting to view the blog threw up a blank page!

Luckily I could still get to the admin pages, so I knew my database was still OK (of course I hadn’t bothered with a backup, so I was worried for a minute.) A couple of other people had the same problem on the WordPress forums, but no solution was forthcoming there.

It turns out that part of the upgrade process had overwritten my index.php file with an almost empty file that contained only comments. Whatever caused this problem (db upgrade? Who knows?), it went away when I copied the file afresh. I am starting to see why most people use a dedicated blog hosting service…

I think everything is working now – let me know if you see anything weird.

Safari 4 is Pretty Good

Safari 4 has been out for a couple of days now, and I must say I am enjoying using it. On the Mac, Safari has always had a great overall browser experience but Firefox always managed to stay my weapon of choice for viewing the Internet. This may change, Safari 4 is a very nice piece of software.

Apple is clearly wanting to make Safari an integral part of the Mac experience – Safari is very well integrated into the Mac OS (you can use Spotlight to search your history, passwords are stored in the keychain, etc), and the UI has all the polish you would expect from Apple. I particularly like the graphical Top Sites view that Safari presents when you first start it.

One thing I have always liked about Safari is the way it renders text and graphics. It always seemed to be just that little bit more polished than other browsers – correctly anti-aliasing fonts and respecting the embedded colour profiles of images. In my opinion Safari is still the best looking browser.

Apple are making a big song-and-dance about how Safari 4 is much faster than other browsers. What they mean is that they have included a very good Javascript JIT compiler which speeds up script-heavy sites by a large margin. This is excellent news, but Safari is hardly alone in focusing on Javascript performance and very recent versions of other browsers have very similar performance.

On Windows, Safari is something of an oddity. It works just as well and still renders sites better than most other Windows browsers, but its awkward neither-Mac-fish-or-Windows-fowl UI doesn’t help. The Windows version also lacks the smooth GUI animation that makes the Mac version so pleasant to use. Apple are doing their best to push Safari onto iTunes users, but I can’t see it taking off except among web developers, Safari’s built in web development tools are very cool.

There are still a few problem areas. Safari doesn’t seem to enjoy displaying animated GIFs, which often stutter before they are fully loaded. It very occasionally beachballs for a second on some pages, not all the time but enough to be annoying.

Finally, another rant about the HTML video tag (since the last one got quite a bit of attention): Safari supports the video tag but farms out the video to Quicktime. I suppose this is better than nothing, but you can tell that it is not well integrated. Videos do not show up in the list of page assets and it is clear that Quicktime is downloading the video itself, bypassing the browser’s cache. On top of this, performance is quite poor when the Javascript controls are used. The video quality is top-notch, but the experience is disappointing.

It sounds like I am dumping on Safari, but really they are minor niggles in a sea of greatness. I still think Firefox has the edge (particular Firefox3.5, which is shaping up nicely) but you could do worse.