Archive for May, 2007

More free gems for the Mac

May 2007 – March 2008 Apple () • 948 views • one response

It must be that time again already… here we go!

MagiCal

Everyone needs a calendar to hand. In Windows using the time in system bar seems to be the quickest option although it’s obviously not meant for that and one false click sends you to the future.

Vista and OS X come with widgets to do this but there is something just satisfying about this calendar-in-the-menubar app.

AppDelete

Mac OS X comes with a built-in package installer that won’t uninstall applications. Curiously NextStep had just that but it never came across to OS X with everything else although the installer does still write the receipts (logs).

Perhaps Apple believe dragging the .app to the trash is enough but if you like to also junk the various other files occasionally held in places such as in /Library/Application Support/ then AppDelete is for you.

App Update widget

This cool widget checks Apple, MacUpdate and VersionTracker for new versions of the applications you have installed and lets you download with a couple of clicks.

It’s a little buggy sometimes at recognising you already have that version especially when the developers use build numbers etc. but the author anticipated this so there is a “yeah that’s the version I have” option to let it know.

kuler colour widget

Adobe’s web site exists to help you create sets of 5 matching colours, name them, share them and rate them. It’s the Flickr! of colour palettes and comes with a handy widget for OS X.

[)amien

ActiveRecord, the ugly design pattern

May 2007 – September 2009 .NET (, ) • 1,900 views • 3 responses

I first encountered the Gang of Four Design Patterns book back in 2001 when a friend lent me a copy. I didn’t immediately get it, most likely because my object oriented experience up to that point consisted primarily of small Delphi applications.

In the last few years I’ve been working on much larger systems and have come to appreciate design patterns enough to get my own copy and also to invest in Martin Fowler’s excellent Patterns of Enterprise Architecture which provides higher-level patterns aimed at large data-driven applications.

One of the design patterns presented, and indeed a core component of the Ruby on Rails framework, is that of the ActiveRecord which attempts to provide object-relational mapping.

It achieves this by specifying a single class per database table where instances of that class represent a row in the table – exposing a property for each field the row has in the database. Each ActiveRecord instance is therefore effectively a domain/business object.

So far so good but then the ActiveRecord pattern ignores the single responsibility principle by specifying that the object should also include a bunch of static methods for managing the table’s contents and retrieving instances.

What you end up with is one object with two distinct responsibilities separated by nothing but the static keyword. Static methods and fields can serve a useful purpose but dividing up responsibilities isn’t one of them and neither is to provide global-like access across your application (Singleton abusers take note).

I can think of at least two reasons why gluing two candidate objects into one physical one using the ‘static’ split causes ActiveRecord to suffer with problems:

Multiple connections

Sometimes an application requires connections to more than one database (e.g. reporting, aggregation, upgrading tools, per-user switching of database in a web application).

Static methods often rely on static fields which means you’re going to have trouble making the

data you’re going to have trouble making them behave like objects.

Inheritance mapping

There are three types of inheritance mapping techniques available.

  1. Concrete Table Inheritance – one table per concrete class containing columns for all fields of the class regardless of where they are declared
  2. Class Table Inheritance – one table per class in the heirarchy containing columns for fields of the class they are declared in only
  3. Single Table Inheritance – a single table for all classes in the heirarchy containing all columns for all possible subclasses many of which will be null

Concrete Table is most likely where the tables created by the parent classes would have little or no value and Class Table where they do.

Single Table is what ActiveRecord implementations such as Ruby on Rails tend to use although quite how it works I’ve yet to discover… Does the parent class magically know enough about it’s child classes that it’s static methods can handle the update/select/delete? Can I ask the parent class for all objects and get a mixed collection back? <shrug>

Alternatives

Fowler presents a number patterns as alternatives and many object-relational mapping (ORM) solutions including LINQ for SQL utilise them.

[)amien

Hiding secrets behind the law – DRM, AACS and the 16-byte key

May 2007 – March 2008 Entertainment, Hardware, Internet (, , , ) • 1,167 views • one response

It surprises and annoys me when I hear of individuals or companies trying to use the law to hide secrets. Surprise at the sheer stupidity and annoyance that tax payers money is used in the process.

The latest secret under suppression is a short 16-byte key which locks away the content on HD-DVD discs that only licensed software and hardware can play it back and prevent you from making copies.

This type of protection used to be called copy-protection but these days it goes under the equally unpopular name of "Digital Rights Management (DRM)". It enforce the copyright holders rights whilst denying you yours and does it in such a way that in some countries re-asserting your legal rights means you end up breaking others.

The AACS Licencing Authority believe they can now protect by law what they failed to protect using technology. This is particularly amusing because their predecessor, the DVD-CCA, failed on both counts when the encryption on DVD was broken in 1999 by an enterprising trio. Apple gets it and is going down the DRM-free route and not treating their customers like criminals.

Basing an entire business model on keeping a sequence of characters secret defies belief and thinking you can wipe the secret off the face of the internet once it’s out is laughable especially when you consider the infinite number of ways you could represent it. The AACS are at it anyway with take down notices to the likes of Digg and others. Amusingly the take down notice itself includes the ‘magic key’.

Alternative 16-byte sequence where each byte is an offset on the previous one is "09 F0 18 F1 9B D7 6F 78 7D 69 15 6F 9E F3 32 38" which if run through the following program yields a certain magic key.

class Program {
    static void Main(string[] argv) {
        byte b = 0;
        string key = string.Empty;
        foreach(string a in argv) {
            b += byte.Parse(a, System.Globalization.NumberStyles.HexNumber);
            key += string.Format("{0:x2} ", b);
        }
        System.Console.WriteLine(key);
    }
}

[)amien