Process Based Development

I have come across recently a way of developing software in an “agile” way. Stories are written, encapsulating some functionality and subsequent stories enhance or build on those areas. They are tested and deployed for review during and at the end of the sprint. Everything is working as you would expect. You work on a process till it is “finished”.

Is it really finished though?

However, what if there are dependant processes down stream? Can we say that the 1st process is done? It is like wiring a house without ever checking that switch A turns on light A. You wait till the whole house is built and decorated before finding out a) it isn’t finished and b) you need to make a hole in that wall to get into the wiring again. (I don’t know if this is strictly how you would fix that issue, i am not an electrician! Hopefully the analogy holds though).

An alternative process would be to develop part of the 1st process, then implement it’s usage in process B to verify a) it works and b) assumptions on it’s structure/format/workflow are correct. For instance we have a process to define some business rules, set parameters, data to be used in another process. We then implement a basic usage of those business rules to show them being applied and verify that amending them gives us the desired results. This is kind of like Unit Testing (or even Test Driven Development) for the application from a end to end point of view. We write enough code to add or edit some of these business rules, then enough code to test that their usage is correct. We can keep iterating over this adding more features and testing their usages.

This approach can catch unexpected behaviour and quickly highlight where additional refinement or changes need to be made. We also have a fully working system (basic at first, gaining more business value over time).

Decorator or Russian Dolls (part 2)

It has taken a few weeks, but i have finished an implementation of “extras” in the making a cuppa instructions app. Part 1, for those that missed it. All the code can be found on github, https://github.com/chrishey/CupOfCoffee-DecoratorPattern

So ideally i wanted to keep a similar style to getting the extras, passed in via the command line. I also wanted to be able to specify via the command line what beverage i was making. So lets tackle that last one first.

First i brought in a command line args parser (see the git repository to see how it works) to read the arguments and give me an dictionary of arguments and their values to work with. In our initial Main method now we can read the “drink” argument and from there initialise the right beverage type class.


if (args.Length == 0)
{
Console.WriteLine("Sorry, we couldn't find your beverage");
}
else
{
var commandLineArgs = new CommandLineArgsParser(args);

switch (commandLineArgs["drink"].ToLower())
{
case "tea":
var tea = new Tea();
tea.CuppaFather();
break;
case "coffee":
var coffee = new Coffee();
coffee.CuppaFather();
break;
default:
Console.WriteLine("Sorry, we couldn't find your beverage. Would you like a cuppa Tea, Father?");
break;
}
}

We can now run the program to give us instructions to make us a cup of tea

makebrewdrink

Moving swiftly on past that small hurdle, I started thinking (and hacking) about how to get extras in. I wanted extras, whatever they were to be an IStep, so i could chain them. I also need a quantity potentially on an extra i.e. spoons of sugar. I tried a few ways to do this and after several failed attempts to make it work 100% cleanly i ended up with the following.

An extra always has a quantity, so let’s create a class to hold that.


public class Extra
{
protected readonly int Quantity;

public Extra(int quantity)
{
Quantity = quantity;
}
}

We can now use this as base for all extras and inject the quantity in via the constructor. I also wanted the extras to implement IStep so i can keep calling .Do() if another IStep is injected into it.


public class AddSugar : Extra, IStep
{
private readonly IStep _step;

public AddSugar(IStep step, int quantity):base(quantity)
{
_step = step;
}

public void Do()
{
Console.WriteLine(string.Format("Add {0} spoons of sugar", Quantity));

if (_step == null)
return;

_step.Do();
}
}

As you can see here, we take an IStep instance and a quantity in the constructor of an extra. We pass the quantity to the base, print out our instruction and then see if we have a subsequent step to call. I now needed to put this together with the command line arguments along the lines of Make.exe -drink tea -sugar 2. Due to the quantity constructor parameter it wasn’t just a case of chaining the extras into the Tea/Coffee class, also there might be multiple extras and i need to know their names and what instances to create.

My solution was to read any extras off the command line arguments.


var commandLineArgs = new CommandLineArgsParser(args);

var extras = GetExtras(commandLineArgs);

Where GetExtras is as follows:


private static Extra[] GetExtras(CommandLineArgsParser commandLineArgs)
{
var extras = new List();

if (commandLineArgs["sugar"] != null)
{
var sugar = int.Parse(commandLineArgs["sugar"]);
extras.Add(new AddSugar(null, sugar));
}

return extras.ToArray();
}

Not ideal and it does “itch” with me a bit, but it works, which some of my other attempts didn’t. In this example we aren’t passing in another step, just the amount of sugar off the arguments. I also have to know the name of the extra to deal with it, i couldn’t see how to do this dynamically, this might be part 3! 🙂

Now the Tea and Coffee classes need to accept these extras to add the instructions.


public class Tea : BrewUp
{
private readonly Extra[] _extras;

public Tea(Extra[] extras) : base (new FillKettle(new BoilKettle(new AddTeaBag(new AddMilk(null)))))
{
_extras = extras;
}

public new void CuppaFather()
{
base.CuppaFather();

if (_extras.Any())
{
foreach (var extra in _extras)
{
var step = extra as IStep;
if (step != null) step.Do();
}
}
}
}

We move through the ISteps via the BrewUp method of CuppaFather and then if we have extras we loop through them and call any subsequent ISteps chained onto them.

makeabrewwithextras

We can now get extras like sugar printed out in our instructions.

Any feedback or possible tweaks to the solution are very welcome. The code is there on Github, fork it and send a pull request or get in contact.

Thanks for reading….i am off to make a brew!

Taking the lead

I used to lead a team at an agency in the Cheshire countryside before my latest move took me to Altrincham. I was therefore directly responsible for people’s careers and shaping how back end code was written on software projects. I know you can say people are responsible for their own careers, but I think senior people need to help steer others in the right direction and offer advice. You can’t make people learn, but you can inspire them and keep them on the right track.

Recently I began thinking about my role there, since now I have my own projects to deliver and in terms of mentoring I am not directly responsible for other developers careers, at least officially. Back when I was responsible we managed to get the team built out to enable me to help out of projects that needed support and spend time pairing with others, making sure we use the right technology for the project and have the necessary time to complete the work. I hope this allowed me to spend valuable time with the 5 developers (all lovely lads!) I had in the team and work with the other “leads” to make sure we collaborated properly to build the best solutions efficiently. I believe this will have benefited everyone involved as I got their feedback and could discuss how and why we could solve a problem better, plus we grew to be a tight unit as a team. By this I mean we would pick up each others work easily and want to put in the extra effort for each other in times of tight deadlines. It also gave me the chance to see the bigger picture and introduce TDD, code coverage and continuous integration and deployment.

This wasn’t always the case, at first when the team was small, the workload wasn’t much smaller. I had projects to deliver myself as well as help out on others, plus I wanted to give them space to develop their skills with out fear of failure. At times I got too into my project (especially as it was a big client and had very tight deadlines) and wasn’t able to spend the time I needed with others in the team when they really needed me. I still maintain to this day that this impacted badly on 2 the members of the team I had at the time. They were left to fend for themselves and although they did their best they needed direction and support.

I was lucky that the company allowed me to build the team out and become less project dependant as the role of leading a whole team AND delivering projects 24/7 just wasn’t going to work, at least not in this case. By being able to put in the extra time and effort to bring others on we ended up happier, more efficient and better skilled as a team.

I would be interested to hear other developers views on this, if you are prepared to share them?

Thanks for listening!