Coding is like gardening...

Archive for December, 2008

Do what you love

I have always had the idea that you’re supposed to love your job. Until recently I did not know very many people who shared my view. I worked very hard at trying to find a way to love what I was doing – always finding little mental tricks to convince myself that what I was doing was enjoyable and interesting. Everybody around me was just earning a living, counting the hours until home time.

That changed six months ago. I stumbled across a job description quite by chance, and something shifted in my mind. Somehow I just knew that this was exactly the kind of job that I should be doing. I sent my CV, requested an interview and told Chris that I wanted to work for Eden Development. Although there was nothing particularly wrong with my previous job, I had no hesitation in handing in my notice. I realised that, rather than trying to love what I was doing, I could do what I already love.

Now I work with people who are here because they want to be here. We do what we love, and we take great pride in it. I get to do what is effectively my hobby – every day – and become really good at it. As an added bonus, I even get paid for it! I work in beautiful surroundings, just a short walk away from my home.

If reading this post makes you feel envious, maybe it’s about time to start looking for a job that you love!

New website and blog theme!

We’ve recently redone our entire website and our blog theme. This blog is now much more integrated with the website and promotes the same messages.

Thanks Aimee for the great wordpress theme and the excellent job on the new site – she put it all together inside a week. Thanks also to Super User Studio for the fantastic fresh design.

Just also to mention that we shut down the office for Christmas on the 22nd of December at 5pm, and will be back up and running fully on the 5th January, bright and early at 9am. Have a great Christmas and fantastic New Year!

–Chris

Genetic Algorithms: Approximating Fine Art

70000 attempts in...

70000 attempts in...

For a bit of fun, I decided to re-implement Roger Alsing’s approximation of the Mona Lisa in Ruby (my language of choice).

Rather than the brute force approach taken by the original implementation, I’ve gone for a full genetic algorithm solution, with crossover, mutation and population propagation. It’s been lots of fun :)

If you’re interested, grab the code here. It’s all open source: if you fancy modifying it, feel free to do so!

Update: Added work in progress image.

Update: Replaced work in progress image. This one only uses 50 triangles!

“History will be kind to me…”

“…for I intend to write it.” — Sir Winston Churchill

I love this quote.

To me it sums up the idealism that caused me to go into this business in the first place: If you don’t like your story, or the world around you, then change it!

I saw a lot of average web application developers out there, and I decided the whole ‘web business’ thing could be done much better. So I set out to create a great company full of great people producing great work, making the experience of web application development that much better for others.

It’s perhaps not the best time in the world to start an average business, but, let’s face it, who would want to start an average business? There’s never a great time to start a bad business, but there’s never a bad time to start a great business.

If you’ve got a great idea for a business, or a charity, or for making a positive difference, but you’re sitting on the fence with it, what’s holding you back? Rather than us vaguely wondering if history might be kind to us (or even notice us at all!), let’s instead take up the challenge and write some history of our own.

Starting at Eden

Not many people can honestly say that they are actually doing their dream job. Many people have dreams and aspirations, and somewhere along the line they end up in a completely different destination. Life just has that way of sidetracking you, without you even noticing. That being said, on September 21st 2008, I walked into my dream job. Everything would be plain sailing from here on, the hard work had already be done getting here in the first place, right? Wrong.

From the first hour I realised that that these guys (and girl!) were good… really good. Not just that, they were talking in a completely different language to that which I was accustomed. Agile Development? Behaviour Driven Design? RSpec? Outside-in? Fixing broken windows… isn’t this a computer company? To say I was confused and a little scared at this point, would be an understatement. I still had a very big mountain to climb, in fact, my journey had only just started.

However over the last few months that I have been here, I have really started to grasp a lot of these concepts. Not perfect, or master them (that takes time and practice) but the value of them and how applicable they are to modern software design has blown me away. The concept of Agile Development and BDD isn’t completely strange and abstract, in fact, it’s quite simple:

  1. Write a story to explain the feature you are adding. (This can be done by the developer or customer)
  2. Run the story (it involves Cucumbers, i’ll explain some other time)
  3. The story fails (no code yet)
  4. Write a spec for the code that you will finally implement (This is the second layer of testing)
  5. Write code

The first 4 steps can be repeated a few times before any real code is actually written. When you do come to write code though, you know it works. How? The specs tell you so. It’s magic. Compare this to how I was taught software development in University:

  1. Write a design document (This explains the entire system and its individual components)
  2. Create UML diagrams and User Specifications for every Class in the system and how they interact
  3. Write code

Fewer steps, it must be quicker. What I didn’t mention was that the first two steps can take months alone. Often by the time that you actually come to write some code, a feature of the applications design has now changed, this means that has to be re-written and the diagrams all updated. Further delays. This monolithic approach is largely inefficient and frustrating!

So Agile Development works out better for the customer and better for us programmers (we actually get to do what we love doing!). Coupling that with strict testing at every step ensures fewer bugs and greater flexibility. You can approach each new feature/problem with confidence knowing that if any change you make breaks another part of the system, it will be caught by the tests failing. This is why the staff at Eden actually love doing what they do. They get to write awesome software, and have fun doing so. Compare this with the Games industry which is full of programmers who are overworked and burnt out. They were in what they thought was their dream job, but really wasn’t. I still have a mountain to climb to reach my new goals, but I’m having a lot of fun doing so!

Eden is a great company, with extremely talented staff. We have lots of really interesting projects spanning many different industries. I think this mountain will be quite fun to climb :)

Under the hood: RSpec as your early warning system

This article is part of our ‘under the hood’ series, where we examine coding concepts and techniques related to how we build our products and services for our clients. If you’re of a technical bent, then do check out other articles as they appear in our ‘under the hood’ category.

One of the most useful aspects of RSpec and BDD is how it can highlight areas of your code that are obvious targets for improvement.

When we write our specs before our code we are effectively writing the API, the contract that our code must fulfill. It’s often the case that if this contract is hard to write, or just looks clumsy, then there may be a better way to express it.  This makes RSpec our first way of detecting code smells.

Perhaps the easiest type of code smell to detect with RSpec is Law of Demeter violations. Imagine a simple Ruby on Rails task management application. Tasks can be owned by Users. There may be many places where we would want to show who owns what Task. The simplest way to do this in Rails would be to use a belongs_to association to expose the attributes of the User to the Task. This makes it trivial to get the name of the user who is assigned to a task:

class Task < ActiveRecord::Base
  belongs_to :owner, :class_name => "User"
end

# to get the owner name:
task.owner.name

While this is easy to write, it would make our specs more complex. Anywhere we wished to mock the name of the owner we would have to write something like the following:

task.stub!(:owner).and_return(mock_model(User, :name => "Bob Smith"))

There’s a lot of noise in this line. We’re creating a mock object just to produce the name of the user. Typing and maintaining test code like the above just seems unnecessary — we’re mocking more than we need. Perhaps worse, it doesn’t express our intentions clearly. We’re asking the task to return its owner, then asking that owner to give us its name. Instead of this approach, we can define the contract as we go and we can actually express our intention:

task.stub!(:owner_name).and_return("Bob Smith")

This makes our tests look tidier, but it actually has a more beneficial side effect. Even though we now have to write more code (speccing then adding the owner_name method to the Task class), it’s now the Task’s job to find the name of its owner. This makes our code more maintainable. For instance, imagine that not every task has an owner. With our original code, anywhere we explicitly used the owner association we would have to change the code to:

(task.owner.nil? ? "No Owner" : task.owner.name)

If this was used many times throughout our code base, we’ve suddenly got a large number of places to find and test this code. By defining the owner_name method early we avoided this problem because there’s only one place that now has to deal with the messy business of finding the name of the owner. Our other specs and stories aren’t broken because they can still happily call the owner_name method without worrying about how this is actually handled.

By using RSpec to help us separate out what information we want from how we get this information, we’ve made our codebase just a little bit cleaner and more maintainable.

EC2, load balancing and fault tolerance

So we’ve decided to switch to Amazon’s EC2 for our hosting. Not that we’re unhappy with the service that Bytemark have been providing for our cluster, but EC2 offers a degree of flexibility, and hardware fault tolerance that you just can’t get when you manage the underlying virtual instances yourself. We’ll be making the switch for most of our hosted services just after Christmas.

The one thing that EC2 could do with is a fully fault-tolerant solution for clustered websites. We’re not able to truly factor out the single point of failure when load balancing. We’re getting round this by keeping another load balancer up and running as a spare, and automatically remapping the IP addresses should the first load balancer go down.

This will cause a maximum of a few minutes outage in the event of any server hardware failure, which is better than our existing setup, but it sure would be nice if EC2 handled this for you…

Having said that we’re pretty happy with the way EC2 works. I’m a full believer in the concept of Utility Computing – eventually computing power could well be provided in much the same way electricity is today…