2009
10.29

My housemate Stu Quin created and recently open sourced “Sourced”.

About

First release of Sourced Editor, my open source, cross platform source code editor. Sourced offers support for editing files on remote (SFTP and FTP) and local file systems.

Features:

  • Support for SFTP and FTP(partial)
  • Built in terminal for remote SFTP connections
  • Open projects automatically saved and restored on next use
  • Support for public key authentication
  • Syntax highlighting and auto completion for range of languages (php, css, js, xml/html, ruby …)

More about Sourced here: Stu’s Blog Post on Sourced.

Porting to Mono

I’ve been looking for something interesting to do with Mono and Moonlight for a while now (that is not directly related to my work) and I decided an open source project would be the way to go.  While Stu is up to his neck with his final year studies, I decided I was going to port the app to Mono in my spare time.

Why Mono?

I love C#.. but not only that I am going to toy with the idea of implementing the UI with Moonlight.  Mono is something I am 100% behind and Miguel de Icaza and his Novellian army are legends, this is why.

It’s already written in Java what is the point?

Purely educational, experimental and to get another Mono app out there.  This port will be very much open source so it will be free for people to hack away with.

Time to Code!

Goodbye blogland!

2009
10.28

I like to learn to write code by writing software, I like to learn about writing software by writing about it.  My goal is to build a series of posts which will reflect the knowledge I have gained regarding this topic of Fluent Interfaces and Internal DSLs.

Disclaimer: Authorship is not equal to Authority.  I don’t claim to be an expert in this domain.  I’m merely learning by doing so take what I write with a pinch of salt!

Fluent Interfaces & Fluent APIs

A fluent interface to me is a the way you interact with a class in a fluent fashion.  A fluent API is how you interact with a framework of classes in a fluent fashion.  In all reality the terms are interchangeable with one another.

Over the last month I have been thinking a lot about fluent interface design in C# to create a DSL for an “Fluent” API I will be working on.  I am starting to see more and more “Fluent” APIs emerging in the .NET space.

I am currently researching quite heavily in this area and I will be blogging about the different approaches that can be taken to develop an effective Fluent API.  I want to know first hand how to create structured and compiler controlled sentences, the positives and negatives of doing so by experiencing the process of developing and developing with my own Fluent API.

Definitions

“In software engineering, a fluent interface (as first coined by Eric Evans and Martin Fowler) is a way of implementing an object oriented API in a way that aims to provide for more readable code.  A fluent interface is normally implemented by using method chaining to relay the instruction context of a subsequent call (but a fluent interface entails more than just method chaining).” Wikipedia: Fluent Interface

“Typically, method chaining simply consists of many methods on a class, each of which return the current object itself. This enables invoking another method on the same object immediately, leading to code that may look something like:” Wikipedia: Method Chaining

Simple Fluent Interface

This is a simple example, my goal is to elaborate into more complex scenarios in later posts.

Here is an example of a fluent interface for creating a Coffee, it could be said we are creating a ‘internal’ DSL  for creating coffee.

The first thing to note is that all public methods return ‘this’ in turn allowing us to chain methods together.

public class CoffeeItem : ICoffeeItem
{
    public bool HasMilk { get; set; }
 
    public bool HasCream { get; set; }
 
    public CoffeeSize Size { get; set; }
 
    public ICoffeeBlend Blend { get; set; }
 
    public ICoffeeItem SetSizeTo(CoffeeSize size)
    {
        Size = size;
        return this;
    }
 
    public ICoffeeItem WithCream()
    {
        HasCream = true;
        return this;
    }
 
    public ICoffeeItem WithMilk()
    {
        HasMilk = true;
        return this;
    }
 
    public ICoffeeItem SetBlendTo(ICoffeeBlend blend)
    {
        Blend = blend;
        return this;
    }
}


Lets create an order and test that it works with a unit test.

[Test]
public void CoffeeItem_OrderAJavaSumutraWithCreamOfSizeEpic_ShouldContainSaidAttributes()
{
    var coffee = new CoffeeItem();
 
    //Set Order
    coffee.SetBlendTo(new JavaSumutra()).WithCream().SetSizeTo(CoffeeSize.Epic);
 
    //Assert that order was issued correctly
    Assert.That(coffee.HasCream, Is.True);
    Assert.That(coffee.Blend, Is.TypeOf(typeof(JavaSumutra)));
    Assert.That(coffee.Size, Is.EqualTo(CoffeeSize.Epic));
}


I find this a nice way to write software, and it lends well to test driven development.  Now lets create a Coffee Order which will contain many coffees.

public class CoffeeOrder
{
    public CoffeeOrder()
    {
        CoffeeItems = new List();
    }
 
    public List CoffeeItems { get; set; }
 
    public ICoffeeItem AddCoffee(ICoffeeItem coffee)
    {
        CoffeeItems.Add(coffee);
        return coffee;
    }
}


So now we can create a coffee order which contains the a coffee with its attributes being set in a a sentence.  We can run this inside a unit test like so:

[Test]
public void AddCoffee_WhenPassedACoffee_ShouldContainCoffee()
{
    var order = new CoffeeOrder();
    var coffee = new CoffeeItem();
 
    order.AddCoffee(coffee)
        .SetBlendTo(new JavaSumutra())
        .WithCream()
        .SetSizeTo(CoffeeSize.Small);
 
    Assert.That(order.CoffeeItems, Has.Member(coffee));
}

So that concludes the simple Coffee example.  It is quite contrived but hopefully gives a quick and dirty glimpse at what a Fluent Interface is.

Topics I wish to cover next in the near future:

  • Returning Interfaces to Control sentence structure within Fluent Interfaces.
  • Using Extensions Methods (C# 3.0) within Fluent Interfaces.
  • An overview of Quality Open Source Fluent APIs in .NET and what you can learn.
  • Passing in predicates and utilizing lambda expressions in Fluent  Interfaces.
  • Internal versus External DSLs.
2009
10.26

Introduction:

Don’t count your chickens until they have hatched.

In this case swap eggs for contracts and chickens for payments.

This is a tale of why it is important to secure your work with a contract, being a nice guy can lead to you getting burned if you’re not smart so be careful.

The Story:

Recently I approached an acquaintance that was developing a funky product and was in need of some expertise which I knew I could offer.  I had no real desire to make money from this project as it was something I would do for free.

I informed them I would help develop the product, teaching them as I go along for free if the product was made Open Source. Open Source development would protect me legally as the contributor to the project, whilst benefiting the world (as I like to think open source does).

This was not going to be the case.  I was told as the product was to be commercial, so I put a pretty generous financial proposal for my time which was subsequently “Accepted”.

Things looked good at this point; I was almost counting my chickens for another payday.

I knew from my research into good practises in contracting and advice passed onto me that if there is money involved and a commercial product that (at least) 3 things should be checked:

  • Credibility* of the Client and their ability to pay (Credit Check).
  • The Indemnity* agreement as you could lose it all if things go sour.
  • There is a Contract* which both parties agree to.
    Note: I thought I knew the client and things were very friendly between us so I skipped the Credit Check.

Things were good, spirits were high and I was genuinely getting excited about working on the project!  I had one week to work on this project which was more than enough time.

Things started to worry me whenever my request for a contract was met with odd behaviour.  There was a lot of fluff spoken to me in reply to my solid enquiries to getting a contract sorted.  The client assured me everything was fine and that the money (which I had officially invoiced them for) was on its way to my bank account for the Monday morning which was to be the first day’s work.

Payment didn’t appear in my bank account and it was now Wednesday of the week, nor was there any official response to my invoice.  In the meantime I was working overtime on another contracted project in order to free up time for the contract in question later in the week.  As the delay in payment was leading to time running out for the project to be completed.

At this point I started to throw some functional prototypes together, but I kept them close to my chest as there was no sign of a contract or the payment which would allow to me to start working on the project properly.

The inner sceptic kicked in, and I decided to make it my policy not to work anymore out of contract on this project as things were starting to smell fishy and I believed any time I contributed would most likely go unpaid and I would have been taken for a free ride so to speak.

In the meantime I was working away happily on my main contract which took precedence, so it was not like I was losing anything, but I certainly wasn’t gaining anything other than experience dealing with an awkward client.

I made it clear I was not going to take on any responsibility for the indemnity for the client, for working on this project as I knew the client and they spent a lot of time in the courtroom due to prior projects, and this scared me to be honest.

After seeking advice from people I trust they helped my realise that without a contract I would be powerless to claim for the work I would deliver, not to mention the legal implications regarding IR35 and liability.

My general policy is, if I am to undertake legal liability for a commercial product whilst working as an independent contractor I will obtain Liability / Indemnity Insurance for the project, and this costs more and it reflected in the price for my services, simple.

It was now Thursday and payment was still stalled. At this point I started to question the funding for the project and as I knew the funding was coming from a 3rd party I thought I would risk not having a contract if I was allowed to have a conversation with the funding party in the deal.

As you can see now, what started off as a nice little project and a kind offer on my part to help out a fellow professional turned into a mess.

Friday morning came, no payment.  This meant that if I was to undertake the work at this stage I would be doing so on good faith.

The client wished to meet up and was eager for work to begin.  They thought I was being awkward, but I knew I had to tread lightly and play this smart by not getting involved until it was on paper and I was protected.

At this stage:

I had forgone the preliminary Credit Check on the Client:

- This meant I not sure if they could pay me.

I was willing to commence work in question without a contract:

- This meant I didn’t have a leg to stand on if I did the work but was never paid.

The payment was 5 days late and the client was acting as a middle man without any real answers.  I just continued to play it cool, I had offered enough of a concession at this point that I wouldn’t have a leg to stand on, but at least I was trying to get things going. This being said, I still needed some kind of guarantee as the client’s words were growing increasing empty and the buck was being passed constantly onto a third party who apparently was having issues with the payment (which I found hard to believe from my prior experience with contracts and payments).

So I put it to the client that if they passed on the contact details of the funding party (who was meant to be transferring to payment to me but had not done so to date), that I would get the payment sorted directly with them, iron out any problems and I in the mean time I would commence work regardless of there being no contract nor payment received. I know now that this was me being too nice.

The response I got when I asked to be connected directly to the funding party was "That’s no problem", but without the actual details which would enable me to do so.

When I enquired for the details the response I got was that the whole thing was off.  I breathed a sigh of relief and had a giggle. Can you imagine if I had of worked on good will all week with no payment, no contract, no insurance… only to be told on the Friday afternoon that the whole thing was off.

The Lesson Learned:

Don’t ever sell yourself short; don’t forgo your legal protection and security of payment when the client is being awkward.  You may be like myself and just want to get to the code (or the task in hand whatever it may be), but keep your head screwed on.  If the client is legit they should have no problem agreeing to a contract being signed at the very beginning and actually doing so.

When it comes to the pre-project contract and payments and you find client is constantly not sticking to their promises and/or passing responsibility of the failings onto other 3rd parties, its often wise to question them and get some confirmation that you’re not being taken for a ride. But when things start to smell fishy it generally means something’s up so don’t begin work until your protected via a contract (or at the very least the money is in your account).

Even though I made many concessions to try and get the project started including forgoing the contract signing, and willingness to start without payment, I did make sure I didn’t start until I was 100% sure I wasn’t going to be screwed over, I did so by challenging the client to give me the so called funding party contact details in order to confirm with them what I was being told the entire week regarding the stalled payments etc.

Hope this was helpful!

Feedback:

I’m always interested in hearing what others have to say, so comments are very welcome… please keep them constructive and on topic!

  • The client thinks I was being awkward, do you?
  • What could I have done better?
  • Do you think I acted professionally?

I’m interested in hearing your thoughts, Thanks!

2009
10.23

A few weeks ago I started my company “Holdsworth & Co Consultants”.

I thought this name to be a tad cheesy but it best describes the business, as the majority of the work which is undertaken involved consultancy and the “& Co” refers to the fact in some cases I would subcontract designers and/or other developers in order to effectively complete the tasks at hand.

I found umbrella companies too restricting for my needs, but great for short term contracting, as my business needs include capital expenditure and management which the umbrella company would not allow for under its form of expenses.

So I ran through the business start-up routine of getting up to speed with the small business laws, taxation and recommended practises, then registered with the powers that be.  I have studied Business Studies for 4 years and Economics for 2 so I was well prepared for what was required and process went smoothly.

As a contractor I knew I would have to beware of IR35.  This legislation was brought in to stop people working as contractors when they were doing the job of an “Employee”.  By employee they mean working 9 to 5 so to speak as a part of a particular business, not really as a independent but in the guise of one in order to achieve the subsequent benefits.

A great resource for getting up to speed with IR35, how to avoid it and its implications is can be found here.

The next step for me is to get a business account set up to separate all my business concerns from my personal ones.

It is nice being my own boss, who knows if I’ll keep up the contracting, maybe one of my projects will come into fruition in the near future and I can ride one of those ponies.

I’m gaining a broad spectrum of skills working as a contractor.. and it only enhances my portfolio as a hired gun.. but that is a post for another day.

2009
10.22

Hello World!

I’ve moved my blog now from http://holsee.blogspot.com to my newly purchase hosting from Dreamhost.

Blogger was fine, a vast improvement over Microsoft offering Live Spaces, but so far I have to say I’m very impressed with Wordpress.

I decided I would link to my old blog rather than importing all my old posts.. I don’t know.. I guess I just want a fresh start and my old posts wont be going anywhere so its all good.

Syntax Highlighting

I love changing my themes so I needed to make sure whatever I used for syntactical highlighting had to work with both dark and light themes. I am using the WP-Syntax Wordpress plug-in. I’ll no doubt play with a few others before I settle.  Syntax Highlighter 2.x is another option but I was getting some funky behaviour when I used a Dark them.

For the mean time my code is going to look like this:

C#

public static void Main(string[] args){
	Console.WriteLine("Hi Whirld!");
}

Ruby

require 'rubygems'
require 'sinatra'
 
get '/hi' do
  "Hello World!"
end
 
get '/hello/:name' do
    # matches "GET /hello/foo" and "GET /hello/bar"
    # params[:name] is 'foo' or 'bar'
    "Hello #{params[:name]}!"
end

I plan to blog mostly surrounding my two languages for choice C# & Ruby.. but I’m a bit of a language nerd so there will no doubt be allsorts.

Oh.. I’m looking to look into the space of DSLs and Code Generation so I’ll most likely be rambling about my experiences.

Time to sleep, meeting the bank manager tomorrow to open a business account.. fun never ends.

Goodbye World!