garyshort.org


I am a Technical Evangelist for Developer Express, my work blog is here but this one is more fun. :-)

April 2007 Entries

Developer Day Voting has Begun

The voting for the agenda for Developer day has opened. Pop across and vote for the talks you want to hear.

Technorati tags:

Seeing How the Other Half Live

Tomorrow I'm off down to the London offices of Charteris, along with some other new starts, for a meeting. Should be fun; don't wreck the place while I'm gone. :-)

Technorati tags: ,

AJAX Talk Glasgow

Just a reminder that I'll be in Glasgow speaking about AJAX for the Scottish Developers next Wednesday evening. More details here. If you are coming along, don't forget to say "hi!".

Technorati tags: , ,

Adobe Open Sources Flex

Hmmm the Silverlight versus Flash war just hotted up.

Design Patterns #4 - The Prototype Pattern

This pattern allows you to create an object by copying a prototype instead of "newing" it up. Why would you want to do that? Well, let's say you had an object and the creation of this object was computationally expensive. If you created this object by "newing" it every time, you'd suffer the same creation cost every time. However, if you create it (or a prototype of it) only once and then clone it the second and subsequent times you need it, then you save yourself a lot of computational expense.

The UML model for this pattern looks something like this

Here's an example implementation in C#

using System;
using System.Collections.Generic;
using System.Text;

namespace garyshort.org.patterns.prototype
{
    class Program
    {
        /// <summary>
        /// GS - Define a class to be a prototype 
        /// for our "expensive to create" object
        /// </summary>
        public class MortgagePrototype
        {
            private int _Atribute1;

            public int Attribute1
            {
                get { return _Atribute1; }
                set { _Atribute1 = value; }
            }

            //GS - Lots more attributes making 
            //this object expensive to create

            private int _AttributeN;

            public int AttributeN
            {
                get { return _AttributeN; }
                set { _AttributeN = value; }
            }

            public MortgagePrototype Clone()
            {
                return this.MemberwiseClone() as 
                    MortgagePrototype;
            }
	    }

        /// <summary>
        /// GS - Now add in the extra attributes 
        /// that make a commercial mortgage
        /// </summary>
        public class CommercialMortgagePrototype : 
            MortgagePrototype
        {
            private int _CMAttribute1;

            public int CMAttribute1
            {
                get { return _CMAttribute1; }
                set { _CMAttribute1 = value; }
            }

            //GS - Lots more attributes making this 
            //object expensive to create

            private int _CMAttributeN;

            public int CMAttributeN
            {
                get { return _CMAttributeN; }
                set { _CMAttributeN = value; }
            }

            public override string ToString()
            {
                return "I am a commercial mortgage";
            }
	    }

        public class ResidentialMortgagePrototype : 
            MortgagePrototype
        {
            private int _RMAttribute1;

            public int RMAttribute1
            {
                get { return _RMAttribute1; }
                set { _RMAttribute1 = value; }
            }

            //GS - Lots more attributes making this 
            //object expensive to create

            private int _RMAttributeN;

            public int RMAttributeN
            {
                get { return _RMAttributeN; }
                set { _RMAttributeN = value; }
            }

            public override string ToString()
            {
                return "I am a residential mortgage";
            }
        }
        
        static void Main(string[] args)
        {
            //GS - Let's test the pattern

            //GS - These objects are expensive to create 
            //so create them once here, early on in the 
            //application

            CommercialMortgagePrototype cmp = 
                new CommercialMortgagePrototype();
            ResidentialMortgagePrototype rmp = 
                new ResidentialMortgagePrototype();
            
            //Okay let's create a new commercial mortgage
            CommercialMortgagePrototype cm1 = cmp.Clone() as 
                CommercialMortgagePrototype;

            //GS - And a residental mortgage too
            ResidentialMortgagePrototype rm1 = rmp.Clone() as 
                ResidentialMortgagePrototype;

            //GS - Do work here...

            //GS - Create more expensive objects here...

            //GS - etc...

            //GS - Let's make sure they work
            Console.WriteLine(cm1.ToString());
            Console.WriteLine(rm1.ToString());

        }
    }
}

The output from this implimentation looks like this

Technorati tags: ,

Dave Winer and Virginia Tech

I surfed over to Dave Winer's site this morning, as I do every morning and found an incredibly naive posting from him on the tragic Virginia tech. incident. This surprised me from such an online media savvy person as Dave. In this post, Dave says:-

"The Virginia Tech shooter sent a package of video and pictures to NBC.

In other words, vlogging comes to mass murder, in ways no one anticipated (or no one I know)."

How could you not have seen this coming? Crazy people will do crazy things and they will want their 15 minutes and they will use all possible means to get it. As new forms of media come on stream so the crazy people will use them to get their "message" across.

"NBC should release all of the videos in Quicktime form as downloads."

Oh they soooo shouldn't. NBC are, rightly, starving this shooter of the oxygen of publicity, the last thing we want to see now is copy cat shooters motivated by the infamy surrounding the shooter in this case.

"They’re sifting through them and deciding what to release and what not to release."

As any responsible media publisher should do in times like this.

"GIven enough time the focus will go on their process, much better to just let it all out now, with no editorial judgement."

Focus will not go on NBC's process, as every right minded person understands what NBC is doing here, except Dave, it would appear

Technorati tags:

YouTube to Split Revenues with Users

Here's some good news for us (even though I've not done any for a while) video bloggers.

"YouTube could take an important step toward integrating advertising with its vast library of videos as soon as next week.

Content creators who upload their videos to the site will be offered the option of having short ads shown at the beginning or end, with the resulting revenues split 50-50, according to Howard Lindzon, founder of Wallstrip, a finance-oriented site that distributes videos through YouTube. Key to the new venture will be making sure that those who upload video actually own the rights to it -- which has been a vexing issue in the past for YouTube, now part of Google's Silicon Valley empire."

Technorati tags:

Installing CAB Under Vista

If you are installing the Composite UI Application Block under Vista, you will probably find that the install will fail after an "unspecified error creating solution files" error. The installation will then roll back.

To fix this, turn off the User Account Control in the Control Panel -> Users applet (see image below). Microsoft recommends that you run with UAC turned on, so don't forget to re-enable it after your installation completes. :-)

 UAC_Off

Technorati tags: , ,

Links for April 16 2007

"Time is running out to get the UK in shape to cope with the next wave of net use, says a report."

Source: BBC NEWS | Technology | Broadband challenge faces Britain

This is not new, but what is new is that they are now supporting UK customers.

"Every online merchant has two goals: sell more and spend less. Google Checkout™ is a new way to process transactions that helps you achieve both. Customers who use Checkout can buy from you quickly and securely, using a single username and password - and you can use Checkout to process their orders and charge their credit or debit cards."

Source: Google Checkout - Home

Windows XP to be retired in 2008

"Windows XP will stop being available on new PCs from the end of January 2008."

Source: BBC NEWS | Technology | Windows XP to be retired in 2008

Draft Blogger’s Code of Conduct

Tim O'Reilly has a blogger code of conduct on his site. One of the items is 

"We won't say anything online that we wouldn't say in person."

I say, 'nuff said really, there's no need for anything else.

Source: O'Reilly Radar > Draft Blogger's Code of Conduct

Hospital phone charges up 160%

"A firm that provides phone services at thousands of NHS hospital bedsides is to increase the cost of calls by 160%"

Source: BBC NEWS | UK | Hospital phone charges up 160%

Wait for it though, there's more

"In 2005, the firm was investigated by regulators over its charges, but was cleared of any wrongdoing."

Ah well, that's okay then. :-)

Technorati tags:

Watchdog probes drug distribution

"The Office of Fair Trading (OFT) has begun a probe into the UK supply of medicines, after changes at the world's biggest pharmaceutical firm, Pfizer."

Source: BBC NEWS | Business | Watchdog probes drug distribution

This post, and the one below it, shows why the NHS is still a miserable place to work and to be a patient, despite all the money pumped into it by Gordon Brown's raid on the pensions of future generations.

Design Patterns #3 - The Builder Pattern

The purpose of the Builder pattern is to abstract the complex creation of an object from the object's implementation. In other words, if you have a simple object, let's say a Person, you can construct that object with a simple constructor that takes a number of parameters such as, name, age, address, place of birth, etc.

However, if you have a complex object, say a 747 or a nuclear submarine, then the code to construct that object may swamp the implementation code for the object. To avoid this the construction code is abstracted away from the implementation.

The UML diagram for this pattern looks a little like this.

The C# implementation would be something like this...

using System;
using System.Collections.Generic;
using System.Text;

namespace garyshort.Patterns.Builder
{
    //Define the classes and interfaces
    public class Director
    {
        public ProductBase 
            Constructor(iBuilder builder)
        {
            builder.Build();
            return builder.GetResult();
        }
	
    }

    public interface iBuilder
    {
        ProductBase GetResult();
        void Build();
    }

    public abstract class ProductBase
    {
        private string _Owner;

        public string Owner
        {
            get { return _Owner; }
            set { _Owner = value; }
        }
	
    }

    public class Car : ProductBase
    {
        private bool _Wheels;
        private bool _Chasis;
        private bool _Body;
        private bool _Interior;

        public bool Interior
        {
            set { _Interior = value; }
        }
	

        public bool Body
        {
            set { _Body = value; }
        }
	
        public bool Chasis
        {
            set { _Chasis = value; }
        }
	
        public bool Wheels
        {
            set { _Wheels = value; }
        }
	
        public void Drive()
        {
            Console.WriteLine
                ("Car is driving!");
        }
    }

    public class Plane : ProductBase
    {
        private bool _Cockpit;

        public bool Cockpit
        {
            set { _Cockpit = value; }
        }

        private bool _Fussilage;

        public bool Fussilage
        {
            set { _Fussilage = value; }
        }

        private bool _Tail;

        public bool Tail
        {
            set { _Tail = value; }
        }

        private bool _Wings;

        public bool Wings
        {
            set { _Wings = value; }
        }

        private bool _Undercarriage;

        public bool Undercarriage
        {
            set { _Undercarriage = value; }
        }

        public void Fly()
        {
            Console.WriteLine("Plane is flying!");
        }
    }

    public class CarBuilder : iBuilder
    {
        private Car _Car = new Car();

        public void Build()
        {
            Console.WriteLine
                ("Beginning car construction.");
            Console.WriteLine
                ("Setting owner.");
            _Car.Owner = "Gary Short";
            Console.WriteLine
                ("Building chasis");
            _Car.Chasis = true;
            Console.WriteLine(
                "Building body");
            _Car.Body = true;
            Console.WriteLine(
                "Building wheels");
            _Car.Wheels = true;
            Console.WriteLine
                ("Building interior");
            _Car.Interior = true;
            Console.WriteLine
                ("Car construction complete.");
        }

        public ProductBase GetResult()
        {
            return _Car;
        }
    }

    public class PlaneBuilder : iBuilder
    {
        private Plane _Plane = new Plane();

        public void Build()
        {
            Console.WriteLine
                ("Beginning plane construction.");
            Console.WriteLine
                ("Setting owner.");
            _Plane.Owner = "Richard Branson.";
            Console.WriteLine
                ("Building cockpit.");
            _Plane.Cockpit = true;
            Console.WriteLine
                ("Building fussilage.");
            _Plane.Fussilage = true;
            Console.WriteLine
                ("Building tail.");
            _Plane.Tail = true;
            Console.WriteLine
                ("Building wings.");
            _Plane.Wings = true;
            Console.WriteLine
                ("Building undercarriage.");
            _Plane.Undercarriage = true;
            Console.WriteLine
                ("Plane construction complete.");
        }
        public ProductBase GetResult()
        {
            return _Plane;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            //Test the pattern

            //I want a car and a plane, 
            //so ask the director to 
            //build them for me.
            Director d = new Director();
            Car MyCar = d.Constructor(
                new CarBuilder()) as Car;
            Plane myPlane = d.Constructor(
                new PlaneBuilder()) as Plane;

            //Now make the car and plane do stuff
            MyCar.Drive();
            myPlane.Fly();
        }
    }
}

The output from this pattern looks like this.

Dave Winer, Link Whore?

In this posting, Dave Winer defends the group that issued death threats against Kathy Sierra. Dave says... 

"It's what being American is about, tolerating all kinds of speech, especially stuff we don't agree with and don't like."

This is the old First Amendment thing, you know, where Americans completely fail to understand their own constitution and insist they have the right to free speech.

Firstly, you don't, plain and simple. The First Amendment only guarantees that Congress wont pass laws to limit your freedom of  speech; it doesn't guarantee the right of reply in the press etc.

Secondly, you don't, plain and simple. Not withstanding the above, no one any where has complete freedom of speech. Don't believe me? Okay try these examples. One, try being a war correspondent and try to broadcast the the time and location of an attack you know about. Two, try being a top civil servant and writing publicly about documents that have been sealed for a certain number of years by the government. Three, try being a white supremist and publish a document that calls for white people to rise up and attack blacks. Will you be able to do any of these things? No. Why? Because freedom of speech is not absolute there are limits. Those limits apply in this case too.

If I dislike Kathy and write saying so in fairly graphic terms, that is okay. If I publish a picture of her with a noose around her neck (as those Dave defends did) then that is not simply passing an opinion, that is incitement, and your freedom of speech is, rightly, curtailed in those circumstances.

So, examining the facts here, there is only one of two conclusions to come to. One, Dave Winer cannot tell the difference between passing an opinion and incitement to violence; or two, Dave knows the difference full well and is playing devil's advocate in order to drive links to his site. I know which one I find more likely. Shame on you Dave Winer!

New Work Blog

I've got a new work blog; there's only an introductory post there at the moment, but once I get going I'm going to be writing about MOSS.

Technorati tags: ,

Twitter Updates


    Follow me! :-)
    www.flickr.com
    GaryShort's photos More of GaryShort's photos