Grimey

March 30th, 2009

grimeylarge

grimeyzoom

Amazon Kindle 2

March 29th, 2009

kindle

I pre-ordered a Kindle 2 last month, for two reasons:

1) I wanted to read more.
2) I wanted to have my own, personal Hitchhiker’s Guide to the Galaxy. (Amazon offers free access to wikipedia)

So, I’ve been playing around with it for about a month, trying to gauge how well it works. I’ve read several books with it, and I thought I’d offer my impressions.

Read the rest of this entry »

Free Watchmen Tickets

March 1st, 2009

Best Buy has a nice promotion going on this week: buy any XBOX Live product, and you can get a ‘Watchmen Movie Pack’ for free. This pack includes a code that entitles you to two free passes to the upcoming Watchmen movie.

I purchased 1600 MS Points this morning for $20, and now I have two free passes. Plus, you can use the coupon for ordering tickets online.

Presenter First: Simple Presenters

February 17th, 2009

While reading this article, please keep in mind that I am a novice in using Presenter First.  The following technique has not been fully tested in a production environment, and may have drawbacks that I have not anticipated.


In developing an obscenely large and complicated personal project, I have become a big fan of the Presenter First design pattern.  It ‘clicks’ with me in a way that standard Model-View-Controller and Model-View-Presenter patterns simply have not.

A quick explanation of what makes Presenter First a little different: A Presenter contains a reference to a Model interface and a View interface.  The Presenter subscribes to events on the Model and View.  The Model and View can only communicate with the Presenter by raising these events.  The Model and View do not have any direct reference to each other.  This allows you to test the Model and Presenter logic without creating a View.

I highly recommend reading the Presenter First white paper (PDF) for more details.

In my project, I’ve been trying to follow a test-driven development approach, where I write test cases (using NUnit and NMock2) before I write the actual code.

I immediately ran into issues testing event subscription and event firing.  It was difficult to test the presenter, because it required the test to fire an event owned by the mock Model.

For example, this was my presenter code for a simple History presenter. The goal is the History model fires the MessageLogged event when a new message has been added to the History log, which will prompt the Presenter to call the View’s UpdateHistory function.

public interface IHistoryModel
{
    event Action MessageLogged;
    string Message { get; }
}

public interface IHistoryView
{
    void UpdateHistory( string aMessage );
}

public class HistoryPresenter
{
    private readonly IHistoryModel mModel;
    private readonly IHistoryView mView;

    public HistoryPresenter( IHistoryModel aModel,
                             IHistoryView aView )
    {
        mModel = aModel;
        mView = aView;

        aModel.MessageLogged += OnMessageLogged;
    }

    private void OnMessageLogged()
    {
        mView.UpdateHistory( mModel.Message );
    }
}

To test this, I mocked up a Model and View with NMock2, but NMock2 does not have any direct provisions for firing events that are on mock objects. I googled around, found a way to create MockEvents, and I found myself with a terrible, complicated test case.

To be fair, the Presenter First white paper does recommend that events should not be specified in the interface itself; they should be hidden by a separate function, like ‘SubscribeMessageLogged’. I found this concept ridiculous, but I started to understand why.

After struggling with MockEvents for several days, I had a sudden epiphany that would greatly simplify everything. I changed the Model event to provide the associated data as a parameter (a behavior that was also discouraged by the white paper) and transform the Presenter into a brain-dead connector.

public interface IHistoryModel
{
    event Action<string> MessageLogged;
}

public interface IHistoryView
{
    void UpdateHistory( string aMessage );
}

public class HistoryPresenter
{
    public HistoryPresenter( IHistoryModel aModel,
                             IHistoryView aView )
    {
        aModel.MessageLogged += aView.UpdateHistory;
    }
}

And… that’s it. The Presenter doesn’t even need any additional methods outside of the constructor!

The test case is super simple as well:

[TestFixture]
public class HistoryPresenterTest
{
    [Test]
    public void Constructor()
    {
        var lMockery = new Mockery();

        var lView = lMockery.NewMock<IHistoryView>();
        var lModel = lMockery.NewMock<IHistoryModel>();

        Expect.Once.On( lModel ).EventAdd(
            "MessageLogged",
            new Action(
                lView.UpdateHistory ) );

        new HistoryPresenter( lModel, lView );

        lMockery.VerifyAllExpectationsHaveBeenMet();
    }
}

The mock Model expects that it will be connected to the View’s UpdateHistory method, and that’s all of the testing that is required. There is no need to raise the MessageLogged event, because that would simply test the functionality of C# events.

The advantage of this simple presenter is even more profound as you add new events to the Model and View. Now, all that is needed is one event, one method, one line connecting the model and view in the Presenter, and one line in the test case.

As long as each event can be tied to a corresponding method, this makes writing presenters (and their tests) extremely simple.

Simple Presenter Example Source Code (26 KB, requires Visual Studio 2008 and Nunit 2.4.8)

Review: Gran Torino (Movie)

February 9th, 2009

Comedy of the year, until the third act.

Helen: The Blind Chicken

February 8th, 2009

Say hello to Helen.

Helen Introduction

She is perched outside of the chicken pen.  She is blind.


Last weekend, the Michigan weather had warmed up considerably (considerably for Michigan), and it was above freezing.

As the sun rose in the sky, my father opened the large door to the chicken pen.  The chickens gradually wandered out, and mingled about outside for the afternoon.  They enjoy wandering about the yard.  Surprisingly, the cats don’t bother them at all.

As afternoon darkened to evening, my father herded them back into the pen.  Alas, one of the chicken’s poked its head outside for another second, and was subsequently rewarded by having its head squished quite thoroughly as my father swung the large door shut.

For reasons that remain unclear, my mother took it upon herself to care for this chicken.  She set up a small box in the basement for it to stay in, and fed it milk.  As the days went by, she grew more attached to it, and even gave it a name: Helen.

Helen Being Pet

Alas, Helen cannot see, and is a rather daft.  She responds to sounds and touch, but primarily spends her time standing in one spot, turning around in circles.  She will not eat for herself, and my mother must feed her milk.

Helen Closeup

As you can see, Helen isn’t looking so well.  One of her eyes is missing, and one is very cloudy.  Her crown is blackened and flaccid.

Kool-Aid Disposal: Strawberry Kraft Macaroni & Cheese

January 14th, 2009

Ingredients

  • 1 Kraft Macaroni & Cheese box
  • 1 Strawberry Kool-Aid packet
  • 4 tablespoons Imperial butter
  • 1/3 cup 2% milk

Preparation

Adding the strawberry kool-aid at the same time as the dry cheese mix felt like a horrible, horrible idea.  So, in order to give this a chance at being edible, I decided to pour the kool-aid in just as the water started to boil.

With every second, I feared that a police officer would bust down my door and assume I had a nice pot of boiling blood going.

With temporary insanity as my copilot, we started takeoff procedures.

Yep, the kool-aid seemed to stain the macaroni just fine.

This was when I started to get that ‘what the hell am I doing’ feeling in my kidneys.  The fully stained and cooked macaroni certainly looked… interesting.

With a strange, robotic resolve, my arms poured the strawberry macaroni in with the milk and butter.

I had a brief hope that the red macaroni would be completely covered by neon-orange cheese.

A brief hope.

Verdict

Weird, very weird.

The cheesy goodness is there, but it cannot fully mask the strange bitterness underneath.

If you ever had one of those “oh fuck, where’s the milk?” moments after you’ve boiled your macaroni, and you end up skipping the milk entirely, it tastes similar to that.  It’s not nearly that bad, though.

Oddly, I didn’t taste a hint of strawberry until a few minutes after my last bite.  This strawberry hint taunted my tongue for the rest of the day.

I actually thought I had ate it in entirety, but long after the sun fell from the sky I noticed half of the batch remained.  This remaining portion sits in my refrigerator.  Waiting.

Kool-Aid Disposal: Black Cherry Mountain Dew

January 5th, 2009

From Left-to-Right: Mountain Dew (2 Liter), Black Cherry Mountain Dew (2 Liter), Black Cherry Mountain Dew (Glass), Black Cherry Kool-Aid

Ingredients

  • 1 Mountain Dew 2-Liter
  • 1 Kool-Aid packet (Black Cherry)

Preperation

I shoved a funnel down the just-opened Mountain Dew bottle’s throat, and gently sprinkled some Black Cherry Kool-Aid.  It was interesting; the Kool-Aid particles appeared to float on top of the Mountain Dew, but some particles would occasionally shoot downwards, and gently rise again.  Seeing that it did not appear to fizz out of control, I poured in the remaining Kool-Aid dust.

It then proceeded to fizz out of control, sort of.  It bubbled up something fierce, and overflowed the bottle, but it wasn’t nearly as bad as opening a freshly-shaken bottle.

It did result in some awesome stains on my hands: we’re talking movie-calibur bloody-cut special effects work.  I fear to contemplate what would have happened if I chose to do this over a carpeted area.

Also, because of all of the fizzing, the Kool-Aid essentially mixed itself into the Mountain Dew.  No stirring required.

Verdict

I remember when I was a young lad, and I started making Kool-Aid on my own.  Surely, I thought, two packets of Kool-Aid would make it taste twice as good?  If you haven’t tried that… you should.  I’ll wait.  Come back when you’re done.

Twiddle dee, twiddle dum.  Dee doo gum.

Oh, you’re back?  Yeah, it doesn’t work like that at all; it ends up as a bitter, nasty concoction.  I was afraid that Black Cherry Mountain Dew would be the similar, with too much ‘flavor’.

But, thankfully, the ultra-sugary Mountain Dew works really well with Kool-Aid.  The black cherry flavor overwhelms the Mountain Dew a little bit, but it is very drinkable and tasty.  Its about on par with the Mountain Dew flavors (e.g. Supernova, High Voltage) released last summer.

Kool-Aid Disposal: Introduction

January 1st, 2009

Whilst placing everything I owned into boxes, I noticed that I had a couple dozen Kool-Aid packets sitting in a cupboard.  The last time I made Kool-Aid, I left an unfinished pitcher in my refrigerator for the better part of a year.

Life-Lesson: Kool-Aid can, in fact, get moldy.

I need to dispose of these Kool-Aid packets, but throwing them away just seems like a waste.  So, I’m going to use these remaining packets in unusual ways, such as mixed in food or a non-water liquid.

For example, what happens if you mix Strawberry Kool-Aid with macaroni and cheese?  Something horrible, I’m sure, so I doubt I’ll try that.  But that’s the angle I’m going towards.

Expect to see some of these ratings graphics in the near future:

Good:

Average/Weird:

Bad:

Srsly?

December 31st, 2008

wht th fck