MonoTouch Error – Missing UIKit.h

MonoTouch Error.pngIf you haven’t heard about MonoTouch, then you need to be on twitter. MonoTouch allows you to write iPhone applications using C#! It’s in early, private, beta at the moment but it is very cool with huge amounts of potential.

However, on my first attempt to compile an application I received the following error:

“uikit.h no such file or directory”

UIKit.h is one of the iPhone SDK files. I knew I had the iPhone SDK installed, however it turns out I didn’t have the 3.0 SDK! After installing the latest version, the application compiled without a problem. A note of the future in-case you hit the same error.

UPDATE: Sorry about edits, I was playing around with MarsEdit and the formatting.

Making users happy by taking advantage of what you already have

SpotifyI think Spotify is an amazing service! Spotify have millions of tracks available for you to start listening to over the internet for free! It’s very simple to use, very quick and has a great collection of music – it is now rare that I even have to access my local mp3 collection!

In the UK we have a Mercury Prize for album of the year. 12 albums are nominated, some of which I would have already have listed too but generally there are one or two bands I’ve never heard of. Previously, I would have had search (generally MySpace) to find out more information about these bands and listen to their music.

Today I was reading the Spotify blog and noticed they have put together a playlist of the albums nominated for the prize. Instantly I had a wow moment. They had taken their existing infrastructure and provided something cool, with very little effort or cost to themselves. I can now listen to the artists entire album instead of attempting to find one or two tracks!

The reason for the post is that sometimes you don’t need to implement massive, expensive, features to make users happy.  Sometimes the little touches can make just as much impact. Having the playlist made me happy, it made it easier to access to music which I was interested in. As a result I was compelled to tell people.

If you look beyond making users happy, Spotify could now sell ads based on this playlist – promoting gigs for the artists or even just having the playlist ‘branded’ by Barclay who sponsor the prize.

I was a little disappointed to find that Florence & the Machine’s album was not included. Not sure the reasons behind this but it feels very strange. The label have an opportunity to reach new fans via a cool and growing service. More fans results in increased merchandise sales, increases gig ticket sales, more exposure which will increase the likely hood of people actually buying the album and spending money. It’s not always about direct album sales.

Cancel a cancellation?

I’m currently on a cut-costing exercise and one of the items which needed to go was a premium Ning service. Priorities changed, aims changed and as such it was no longer required.

Finding how to cancel the service was pretty simple task. However, once I was there I felt something was missing. Notice anything from the screen below?

image

In my mind, Cancel is a way of backing out of a decision. In this case, it was a way to confirm.

Logically, it made sense – you are explicitly clicking cancel. However, based on how every other application works I was expecting an OK or Yes button to appear next to it.

It is important to think about what users are expecting to see together with how certain terms might have more than one possible meaning.

Asking is not a bad thing…

I’m all for applications providing users with a streamlined experience, reducing clicks and the amount of dialogs they have to confirm to get the job done. However, sometimes it can go a step too far.

Today, I had to buy a printer. Came home, plugged it in and Windows 7 happily installed the correct drivers – job done. Not quite. Sadly I had left Word open in the background. After continuing to do work on the document, AutoRecovery kicked in and saved the file. At this point I was shown the following dialog.

image

Instantly I had to stop, take a step back and wonder what I had done to cause this to happen. I was confused, and confusion is very bad for a user. I had no indication of what was happening, how long it would take or why it had happened in the first place. I can only assume it was related to the installation of the printer which caused Word to reconfigure itself.

To make matters worse, after it had completed I was then shown this dialog. There is no reason why Word should need me to reboot my machine.

image

Clicking no was my natural reaction given the choice as I was in the middle of working. Word had other ideas.

image

At this point it had back round the cycle at which point I caved and accepted the reboot. After receiving random errors, Word informed me it could not save my work resulting in a loss of work.

Lessons to take away from this.

1) If the action the application is taking is uncommon or could cause the user confusion – tell them. It would actually have been nice to have a dialog saying – “Sorry, we need to do some configuration as your printer settings have changed.”

2) At which point, I should have been given the option of ‘Now’, or ‘When I close Word’. Actions such as configuration are best performed when the user closes the application as they have finished their work and as such won’t mind the delay.

3) If they don’t want the action to happen – make sure you can cope. In this situation Word obviously couldn’t.

4) Finally, always think about how the user will feel when the dialog pops up or an action is taken without their consent.

Worse user experience ever! today so far today.

MEFUnit – Prototype of a MEF Unit Testing Framework

Recently I have been paying close attention to MEF, the Managed Extensibility Framework. MEF is an extremely powerful framework aimed at making parts (internal or external extensibility points) more discoverable.

While I was looking at this, it dawn on me. Unit testing frameworks main role is identifying and executing methods. If that is their main function – how could you use MEF to identify and execute those methods? The result of this pondering is MEFUnit. Like with xUnit.GWT this is located on GitHub and has been mentioned on twitter once or twice.

The Tests

The tests look very similar to any other kind of unit testing framework you might have used. The attribute [Mef] identifies which methods should be executed, and like with any other framework they can pass (no exception), fail (assertion exception) and be skipped (skipped exception).

public class Example
{
    [Mef]
    public void Test1()
    {
        throw new AssertException("Test Failed");
    }

    [Mef]
    public void Test2()
    {
        throw new SkipException();
    }

    [Mef]
    public void Test3()
    {
    }
}

Fundamentally, this is the main concept of most unit testing frameworks. Yes, some have parameterized tests and other such features which are great, but many people got by with just this. When you run the tests, you get the following output.

Executing Tests
Executing Test1… Test Failed
Executing Test2… Skipped
Executing Test3… Passed

Key implementations points of MEFUnit

But how are these methods actually turned into unit tests? The main point in the above example is the MEF attribute. This is simply a custom ExportAttribute. I could have wrote:

[Export("Mef", typeof(Action)]
public void Test() {}

However, I feel creating a custom attribute improves the readability and usability of my framework for the user. It also means if I need to change the contract I can do it without effecting my dependent exports. The second important fact is that the exports are of type Action.  By storing the method references as Action I can executed them anywhere in my code. This is the trick which makes this all possible. It means I can execute each test as shown and report the result to the console.

public void RunMefs()
{
    foreach (var mef in Mefs)
    {
        Console.Write("Executing " + mef.Method.Name + "... ");

        try
        {
            mef();
            Console.WriteLine("Passed");
        }
        catch (AssertException ex)
        {
            Console.WriteLine(ex.Message);
        }
        catch (SkipException)
        {
            Console.WriteLine("Skipped");
        }
    }
}

The Mefs collection is populated via the MEF framework and the use of an Import attribute. Within the class, the property looks like this: 

[MefTests]
public IEnumerable Mefs { get; set; }

As with the Export attribute, I wanted to hide the actual contract I used to import the Action methods. This allowed me to hide the fact I was using AllowRecomposition, enabling tests to be dynamically identify when new assemblies are loaded.

public MefTests() : base("Mef", typeof(Action))
{
    AllowRecomposition = true;
}

When you combine this with the Compose method which hooks together the core parts of MEF you have the core concept of a unit testing framework.

I have to admit, I’m not expecting anyone to actually use this. However, I think it shows some of the interesting capabilities which MEF brings to the table.

xUnit.GWT – Given When Then (GWT) extension for xUnit.net

One of the most important considerations when writing automated tests, especially customer acceptance tests is readability. I have been looking at how you could potentially create more readable tests targeted against C# applications. While I have spoke before about IronRuby and RSpecCucumber as customer acceptance tests for C# applications, this combination still has some performance issues together with an initial ‘fear factor’ for some users.

One of the reasons why I created this framework was based on previous experiences of introducing new concepts. Attempting to introduce too many new concepts to a team unfamiliar with the idea can be a huge challenge. Team members focus too much on the amount of information they have to learn instead of focusing on the concept and how it can be applied.

In an attempt to combat this, I have created a prototype which approaches the topic of creating customer acceptance tests in a similar fashion to cucumber, however in the familiarity of C#. While you could successfully write your tests like this, my aim is to use this as a gateway to move people onto other frameworks such as Cucumber via IronRuby.

The code for this can be found on my GitHub repository. For those of you following me on twitter, you will be aware that this code has been available for a while – I’ve only just managed to find time the time to write a post about the framework. If you want to stay up to date, I recommend to stay up to date is follow me on twitter, GitHub and of course my blog.

Back on to the prototype. It is called xUnit.GWT and builds on top of the amazing extensibility model xUnit has in place.

Example

[Feature("As a user... I want to... So that I...")]
public class This_is_my_story : This_is_my_story_Base
{
        [Scenario]
        public void when_transferring_between_two_accounts()
        {
            Given("both accounts have positive balances");           
            When("transfer money from a to b");
            Then("a should have the total balance of b", () => a.Balance.ShouldBe(3));
            Then("balance of b should be 0", () => b.Balance.ShouldBe(0));
        }
}

The above code is an example of how a test would look with this prototype. This can be executed using TestDriven.NET, ReSharper and the xUnit.Console itself.

First, lets focus on the class. The class has an attribute called Feature. This should define the feature which the various different scenarios relate to. The scenarios are methods within the class.  These methods has been flagged with the attribute Scenario so xUnit can detect and execute them.

Each scenario is then broken down into three different stages. Each of the Given, When, Then statements are in fact method calls with two overloads. One just accepts a string, while the other accepts a string and a delegate.

The reason we can simply pass in a string, is because the associated delegate has already been set within a base class.  An example base class is shown here.

public class This_is_my_story_Base : Story
{
    protected Account a;
    protected Account b;

    public This_is_my_story_Base()
    {
        SetGiven("both accounts have positive balances", () =>
                                                             {
                                                                 a = new Account();
                                                                 a.Balance = 1;
                                                                 b = new Account();
                                                                 b.Balance = 2;
                                                             });

        SetWhen("transfer money from a to b", () =>
                                                  {
                                                      a.Balance += b.Balance;
                                                      b.Balance = 0;
                                                  });
    }
}

The use of SetGiven or SetWhen allows us to store re-usable blocks of code. Using the string as a key, in our subclass we can use the same key to indicate which block of code should be executed. The aim is that these blocks of code should be reusable enough to allow different scenarios to make use of them and as such improve the readability of our tests.

While playing around, I found this sometimes caused too much overhead which is why you can simply pass in the delegate to execute within the method call. Using the explicit approach when defining your Then’Assertions can actually improve the readability.

With this structure in place, we can now start becoming more flexible. One thing I found when working on test harnesses at Red Gate is that you want to write the boiler plate test while it is fresh in your head, even if the actual implementation is not in place. Having these in place can also provide a good indication of the state of the project. If the test is still pending – it isn’t done.

To cope, you can pass in a delegate called Pending. When you execute the scenario the test will be skipped and not executed.

[Scenario]
public void test_marked_as_pending()
{
    Given("one pending block", Pending);
    Then("it should be marked as pending in the report");
}

The same applies in case you haven’t provided an implementation for anyone of the blocks you are attempting for use.

[Scenario]
public void pending_block()
{
    Given(“a block which has been defined”);
    When(“no action assigned”);
    Then(“it should be marked as pending”);
}

Yet, this is not the whole story. Another problem I commonly experienced was with the NUnit report embedded into CCNet. Even if you have take the effort to make your namespaces, classes and methods make sense I still found it difficult to read.

Taking advantage of the more readable tests, I have created a custom XSLT which can be applied to the xUnit report.

With a bit of styling and bold text in the right place, the report can be extremely readable. When the above examples are executed and the transform has been applied, the report looks like this.

Screenshot

You can easily see which scenarios are passing, failing or pending while also taking advantage of the readable blocks of code to provide more context about what was executed.

This is just a prototype. It is only one possible syntax which you could use. As such, I would be really interested to hear your feedback on this. The framework is fully usable, the binaries can be downloaded here. If your interested in the actual implementation, all the code is available on GitHub. If you have any questions, then please contact me via twitter.

Is it wrong to spend £5 on pick n’ mix from Woolworths ?

image

This is the question of the day! For those of you not in the UK, Woolworths felt the force of the credit crunch and went into administration, closing its 807 stores. Woolworths was a national treasure, opening it’s first store in 1909 (http://news.bbc.co.uk/1/hi/in_pictures/7801807.stm). It’s still a sad sight to walk past an abandon store bearing it’s name.

Woolworths was a very well respected brand, however lost it’s way and as a result the product line became confusing – they sold everything and anything?  The stores became confusing and you lost the joy of entering, which I’m sure many of you experienced as a child. Their community moved onto stores like Tesco and as such there was only ever going to be one way it ended.

However! Today it has returned, as a online store at least. But that’s not the interesting part. After seeing the outpouring of love for the brand with people paying £14,500 for the last bag of pick n’ mix, @team_woolies started to utilise social media to connect this loyal following and build a community. @team_woolies have been utilising twitter, facebook and other social media sites to connect the huge following around the brand.

By building a Social media platform, they have allowed people to share their love of pick n’ mix and all things Woolworth! This has created a huge buzz around the brand that has has got people talking amongst themselves and the different aspects and what they loved. The team could have purchased TV and print ads and attempted to force the new relaunch onto people – this would have failed. It would have cost huge amounts of money and most people would have ignored the ads.

Social media has allowed them to build awareness, promotion and a buzz. The results is that they have created a huge buzz around their relaunch with lots of people talking – without Woolworths having to do anything!

image

The Woolies HQ site provides a personal touch to the site and has even gone as far to use Last.fm and Spotify to create Radio Woolies. While they are little things, together they build a great way to engagement with users.

image

Some would consider Radio Woolies just to be a cost centre – a pointless exercise that will never return any money. That is not the point!  The point is to engage. Allow people to feel connected, involved and important. Little things which make people smile are worth the effort for a company to get right! If people love you, then you’re sure to be a success.

Now they have launched, I hope that they keep the buzz alive. Imagine a facebook application which would allow you to list your favourite pick n’ mix items? Not only would this allow you to share your favourite combinations with friends, but also allow their friends to purchase that combination with a single click as an impulse buy?  @team_woolies – if you need help, let me know!

Finally – “Is it wrong to spend £5 on pick n’ mix from Woolworths?” – I was taken away in the moment, the hype and my joy of sweet things… so I hope not.

MySQL – Creating a new user

It’s funny how you forget the simple things when you haven’t done them in a while.

Tonight I wanted to setup MySQL on my Windows 7 machine. The installation was simple and I happily had my root account created. However, I didn’t want to use my root account for development – mainly because I didn’t want the password to be sorted in clear text.

In order to create a new user, I used the command line MySQL client tool which allows me to execute commands against the server. You enter this via the command.

mysql --user="root" ––password

This will then prompt you for the root password. I could have entered this on the command line as well, but again it would be in the clear.

From the tool, I enter the following two commands. The first creates the user, the second assigns permissions.

CREATE USER 'new_username'@'localhost' IDENTIFIED BY 'password';

GRANT ALL ON *.* TO 'new_username'@'localhost';

I can then happily use this new user with my application. I wanted to post this in case anyone else keeps forgetting like me…

DDD South West – Dynamic Languages and .NET and Creating extensible application using MEF

This weekend I attended and presented two sessions at DDD South West.  Thank you to everyone who attended my sessions and the organisers for hosting the event, if you have any questions then please let me know. Slides and code for the two sessions can be found on the posts below.

Creating Extensible applications using MEF

http://blog.benhall.me.uk/2009/05/nxtgenug-cambridge-creating-extendable.html

Dynamic Languages and .NET

http://blog.benhall.me.uk/2009/05/dynamic-languages-and-net-developer-day.html