iTunes Annoyances

September 23, 2006

So iTunes is great. I really like it. But, there are things that are frustrating about it. Here’s the first in a series of posts that let me rant about some of these annoyances.

Podcast handling.

It’s probably not too much of a stretch to say that the moment when Apple added podcatching to iTunes was when podcasting really took off. The way the whole thing hangs together, in typical Apple fashion, is really slick. However:

  • What’s with the utterly annoying behaviour where a podcast is considered to be “played” as soon as you start to play it? This is completely inconsistent with music tracks where you have to play the whole thing. It also makes the option to sync only unplayed podcasts to your iPod completely and utterly useless.
    ipod_podcast_prefs

    Consider the following scenario where our hero, Bob, has this option turned on:

    • Bob is listening to a podcast – let’s say it’s the latest MacCast – in his car on the way home from work. The podcast has not finished playing by the time Bob gets home.
    • Bob fires up iTunes on his Macbook and notices that a new Ricky Gervais episode has been released. As soon as it is downloaded he connects his iPod and syncs.
    • iTunes, in all it’s infinite wisdom, sees that the MacCast episode has been “played” and takes it off Bob’s iPod.
  • Now I’m not a UI zealot But in this dialog, what’s wrong with ‘yes’ or ‘no’?

    stupid dialog

Patterns – The Template Pattern

August 23, 2006

So this is the first in a series of posts that explain the patterns I use in my day-to-day work. Probably the most common is the template pattern. The purpose of this pattern is to control the way in which the inheritors of your class change its behaviour.

Take for example the following class:

	public class Foo
	{
		public virtual void DoStuff()
		{
			ThisMethodMustBeCalledFirst();
			// Stuff gets done here
		}
		
		private void ThisMethodMustBeCalledFirst()
		{
			// Important initalisation stuff here.
		}
	}

Now imagine that someone comes along and inherits from your lovingly crafted class:

	public class Bar
	{
		public override void DoStuff()
		{
			//New stuff gets done here
		}
	}

It is entirely possible that the user of the Bar class will find that the DoStuff method falls over, because ThisMethodMustBeCalledFirst has not been called. Now this could be solved by putting something like this in your documentation:

It is very important that ThisMethodMustBeCalledFirst is called when overriding DoStuff.

A better way is to make DoStuff() a template method:

	public class Foo
	{
		public void DoStuff()
		{
			ThisMethodMustBeCalledFirst();
			OnDoStuff()
		}
		
		protected virtual void OnDoStuff()
		{
			// Stuff gets done here
		}
		
		private void ThisMethodMustBeCalledFirst()
		{
			// Important initialisation stuff here.
		}
	}

By making DoStuff non-virtual and making it now call the virtual OnDoStuff it is now impossible for an inheritor to change the behaviour of DoStuff without ThisMethodMustBeCalledFirst being called!

So how does this apply to my day-job? Well, the framework I’m working on for the future development of tradesimple will have a base class that will contain all the functionality that is common across all processors. Developers of new processors will override an “OnProcess” method which will be called by the base class as part of a template “Process” method. Not only will this allow us to ensure that certain steps are always followed inside that Process method, but that will also enable us to debug problems more easily by dropping in a debug version of the base class. The Process method inside this base class can do whatever it likes (logging inputs for example) without fear that a badly behaved derived class will override it.

More Resources

  • Obviously there’s the GOF book. Most, if not all the patterns I describe will be in this must-read book
  • Also, the wikipedia article I linked to above has some nice examples.

System.Messaging, COM objects and PropertyBags

August 17, 2006

I’m posting this pretty much as a reminder to myself.

There is a bug in VB6 which means that when you try to write a persistable VB6 COM object to an MSMQ queue using .NET’s System.Messaging then it fails with error 0x800A02E0:

Cannot save an uninitialized class. You must use the global InitProperties method to initialize the class, or load the class from a PropertyBag before trying to save it.

The workaround is to call the InitNew method on the IPersistStreamInit interface of the COM object. In .NET however this is easier said than done. The following goo is needed:


using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;

[ComVisible(true)]
[ComImport]
[Guid("7FD52380-4E07-101B-AE2D-08002B2EC713")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IPersistStreamInit
{
    // IPersist interface 
    void GetClassID(ref Guid pClassID);

    [PreserveSig]
    int IsDirty();
    [PreserveSig]
    int Load(IStream pstm);
    [PreserveSig]
    int Save(IStream pstm, bool fClearDirty);
    [PreserveSig]
    int GetSizeMax([InAttribute(), Out(), MarshalAs(UnmanagedType.U8)] 
		ref long pcbSize);
    [PreserveSig]
    int InitNew();
}

You can then go ahead and cast your object to IPersistStreamInit and call the InitNew method. The object will now persist to the queue with no problems (remember to set up your Message to use the ActiveXFormatter though).

Source Control How-to

August 17, 2006

A great series of articles on the hows and whys of source control.

read more | digg story

"Microsoft Still Plans October 2006 Vista Release"

August 16, 2006

Wow, check out some of the comments on this story. I never cease to be amazed at the particular brand of “the world is black and white” stupidity exhibited by extreme fanboys. I particular like the part where “bonch” posts a link to a story (Windows is officially five times more expensive for users than OS X) which has been roundly rubbished by the Mac community.

Anyway, ranting aside, it looks like the “will they, won’t they” ship story for Vista continues. Ho hum.

Mmmm, shootery goodness

January 16, 2006

00078376

So, I’m waiting with bated breath for Black, Criterion’s new FPS. (Apologies for the link, I haven’t actually come across an official site yet). I loved the last two Burnout games, and if they really can do for the FPS what they did for the racer then all will be good. Besides, I’m a sucker for decent sound in games and the gunfire and related effects sound amazing. I could do with more actual footage in the trailers mind you. Around 30 seconds out of 90 are actual gameplay footage. The rest is logos, ratings, and other marketing bumph. Note to EA, must do better!

Update The official site is here.

Another update Ok so it was slightly disappointing. Still fun, but not all it could have been. And what’s with the annoying unskippable cut-scenes every single time you have to restart a level? It got so that I didn’t want to play because I have to sit through a long cut-scene again (saving mid-level is for wimps it seems). Haven’t developers learned that players *hate* this? Argh.


Follow

Get every new post delivered to your Inbox.