Coding is like gardening...

Archive for February, 2009

Billing with Integrity (part 4)

How do you think a client would feel if he got this bill?

How do you think a client would feel if he got this bill?

(You may want to read parts one, two and three first).

Given that “fixed price fixed scope” billing is flawed, a natural next step for many small businesses is to try variable billing. This time we’ll look at some of the pros and cons of such an approach.

By “variable billing” I am referring to the practice of billing per hour (or per day) for your services. It’s a pretty common way of charging out time in the web development industry. Going back to the four variables of software development from my previous post, when billing in this way you are effectively fixing quality (or you should be!), and tying time and cost together. Therefore you are allowing scope and time/cost to vary based on the client requirements.

The advantages

On the surface, variable billing appears to be the answer to all our problems. We don’t have to worry about estimates, because the client is paying per hour, so we’ll just take as long as we need to get things done. Changes in the project are handled easily: we just drop what we’re doing and change direction, so we can give the client the features they want. Goodbye to underbid projects completed for free!

So why is the client often unhappy with this sort of arrangement? Why won’t many clients even sign up to it?

The disadvantages

Many of the advantages are to do with transferring risk away from the developer and onto the client. If the developer is freed from the risk associated with getting a feature done, then that means the client is bearing the full brunt of the uncertainty. Clients want a fixed price, so they can compare you to other suppliers. Just doing variable pricing makes the proposal process very difficult.

There’s also the lack of trust. If you’re just setting up a relationship with the client, they don’t know you from Adam: they have no idea whether whether you’re as good as your word. You might say 2 days for a feature, but if the bill comes in for 4 days, they aren’t going to be happy. It only takes one large unexpected bill to wreck a client relationship.

Another main disadvantage is more subtle. With this sort of approach, a client can sometimes micromanage the project, as they’re rightly concerned about getting value for money. Therefore it’s possible to get inundated with feedback, minor tweaks, irrelevant bug reports and requests for status updates. This burns through yet more of the developer’s time, adding to a client’s bill and dragging down project efficiency. Often clients will want a very detailed breakdown of exactly what time was spent on their project, causing more management overheard.

Conclusion: Useful in some circumstances

Variable billing works well when there’s a large amount of goodwill between client and developer. It doesn’t work so well at the beginning of a client relationship. It’s worked well for us on the two extremes of projects we take on – the very short and the very long:

* Software consultancy, where we’ve been providing short term expert advice on an ad hoc basis.
* Tiny changes, where there’s only a day or two of little tweaks to make to a site.
* Open ended long term projects, where we provide development resource over months/years.

Sometimes projects degenerate into variable billing as the trust grows, a client starts believing our estimates, and everything becomes more informal.

Interestingly, on our most successful long term collaboration using this billing method we have a regular monthly budget which we can’t exceed, but we use that up in a variable ‘per hour’ manner. This is strikingly similar to our current chosen method of billing, which I’ll discuss in the next and final post in this series.

Tune in next time for an outline of our current method (you may want to subscribe for the latest updates). If you’re in a hurry for an “answer”, you could always peek at our pricing pages if you want to know how we bill :) Thanks to Kent Beck’s excellent essay on Optional Scope Contracts (PDF) for many of the ideas in this series, and the feedback I’ve received from various people.

Twitter integration from your Rails app

We’ve learnt a bit about Twitter from writing ykyat.com.

I particularly want to write about how we fetch Twitter user icons. The icons are stored on AWS (Amazon Web Services) and cannot be deduced from the user name. You have to go through the Twitter API to find the image location.

The first thing I tried was the Twitter4R library. This seems to be a very powerful library, and if you were writing a full Twitter client in Ruby you’d definitely want to consider it. It was simple to get the user icons, but the library just felt a little over-the-top for our needs.

Twitter4R seemed to require authentication with every request, and we soon hit the API limit. I realised this is odd because you really don’t need to authenticate to look at the XML or JSON data about a Twitter user. I decided to go back to basics and do it myself. This is the code for parsing the JSON data and picking up the user icon URL:

def icon_url_for_user(username)
  require 'open-uri'
  require 'json'
  buffer = open("http://twitter.com/users/show/#{username}.json").read
  result = JSON.parse(buffer)
  result['profile_image_url']
end

See! Easy!

Most people don’t change their user icon very often, so once we know where to find a user’s icon, we don’t need to ask Twitter for it again for an arbitrary amount of time. A week seems quite sensible. To that end, we created a lookup table in our database to match Twitter user names to their user icon URL. We added an index to the user name column because it acts as the primary key lookup.

When we want to know a user’s icon, we first look up in our table. If we don’t yet have it, or if the updated_at date is more than a week ago, we check with Twitter for the image location. Otherwise we use our cached location.

Fast and easy! :)

How we made #ykyat

Friday 13th February 2009 was going to be just a normal day, as far as we knew. Then Chris arrived at work at 9am and said, “We’re all going to write a new web app today!” The idea for “You know you’re addicted to” had occurred to Chris the previous day, upon realising that checking Twitter before email represents a pretty serious Twitter addiction! Chris thought it might be fun to see what else people were addicted to, and bring the funny anecdotes together in a place where people could rate them and comment upon them.

We had a quick 15-minute meeting where Chris outlined the concept to us and drew some sketches. Tris and I got straight to work on designing the models whilst Chris put together a visual concept. We had lots of discussion about the colour scheme before agreeing on the bright pink. James and Richard were to design the front end, Tris did the backend data manipulating and URL routing. As the person with previous experience in the Twitter API, my part was to get data in from Twitter and send responses out.

By 10:20 we knew this was going to work! Having looked up search.twitter.com for a few select phrases, we discovered that people were indeed twittering about their various addictions!

Data found on Twitter!

Data found on Twitter!

(more…)

Announcing Rails Business (UK)

One thing I’ve always thought missing from the Ruby on Rails scene in the UK is a decent get together of Rails business people – those who run their own businesses like myself. There’s plenty of technical groups, or groups that meet in the evening, but I couldn’t find anything in the daytime.

The best way to get what you want is to do it yourself, right? Therefore I’ve created a meetup group for it. The main aim is to discuss such things as: best practices in running a rails consultancy (of any size), best-practice ruby on rails development/project management, this Rails Maturity Model idea that’s been doing the rounds in the last few weeks, plus anything else that’s relevant.

Anyone who’s interested in the same sorts of issues discussed in this group is welcome to attend. For more details of our first meeting on 4th March, see here.

Coffee Perk

Recently, in addition to my usual work, i have been learning how to make an expresso, latte, cappuchino and americano. I now know all about coffee grinding, tamping and how to steam milk!

This is all thanks to our amazing new coffee machine!

Coffee machine Delicious coffee!

Mmmm, nothing like a lovely cup of frothy, hot Eden Development coffee to get me coding on cold and frosty mornings! :)

If you’re coming to visit any time soon, you can look forward to being welcomed with a delicious cup of coffee of your choice! We even have a sofa and a coffee table! :)

Announcing ykyat.com

Screenshot of ykyat.com

Screenshot of ykyat.com

I’ll blog more about this next week, but just wanted to quickly let you know about our new web application, ykyat.com.

It’s a very simple service built on Twitter. It collates classic ‘you know you’re addicted to…’ jokes on a central website, and allows them to be rated so that the funniest are promoted for all to see.

It was built partly for fun, and partly as a grand experiment in rapid application design and development: we designed, built and deployed the entire app from the ground up in 8 hours 42 minutes. We learnt a lot from the process and I’ll be posting a minute by minute diary with some screenshots next week.

Web development is moving on: are you?

Great article on thinkvitamin.com today, although there was one small point I wanted to quibble:

First of all, for the most part it’s impossible to develop offline ‐ this is because we use hosted services, APIs and most likely you’ll write something that uses some data stored elsewhere on the web.

I disagree — if you’re doing things properly you should be stubbing that API in your test and using git locally, allowing you to work anywhere. Testing the integrated whole must usually be done online, but full integration tests can be always be run later when you’ve done your piece of work and you’re back on the grid.

Exporting from Rails to Excel

There are various methods for exporting data from Rails to an Excel spreadsheet, some more complicated than others.

One easy way we’ve used a few times is to make use of Excel’s ability to interpret HTML tables as spreadsheet rows and columns. For example, i can set up a helper method to turn a collection of tasks into a table in a simple HTML page:

module TasksHelper
  include ActiveSupport::Inflector

  def generate_xls(tasks)
    output_columns = [:title, :due_date]

    returning String.new do |str|
      str << "
"
      str << "
"
      output_columns.each do |col|
        str << "


"
      end
      str << "

"

      tasks.each do |task|
        str << "
"
          output_columns.each do |col|
            str << "


"
          end
        str << "

"
      end
      str << "
#{humanize(col)}
#{task.send(col)}
" end end end

The environment.rb file is going to have to know about the .xls extension:

Mime::Type.register "application/vnd.ms-excel", :xls

The TasksController can now be taught to respond to .xls and send_data as a file for download:

class TasksController < ApplicationController
  include TasksHelper

  def index
    @tasks = Task.find(:all)

    respond_to do |format|
      format.html # index.html.erb
      format.xls {
        send_data(generate_xls(@tasks),
          :filename => 'all_tasks.xls',
          :type => 'application/vnd.ms-excel')
      }
    end
  end

end

When visiting /tasks.xls we will now be given the option to download all_tasks.xls which Excel will parse quite happily as a spreadsheet.

One important consideration: Excel is not overly fond of Unicode, and Rails by default will send data in UTF-8 format. If the data contains Unicode characters such as curly quotation marks, you will get some weird output like “ in the spreadsheet.

Not to worry! We can use Ruby’s implementation of the iconv API to convert to Excel’s preferred format, ISO-8859-15.

class TasksController < ApplicationController
  include TasksHelper

  def index
    @tasks = Task.find(:all)

    respond_to do |format|
      format.html # index.html.erb
      format.xls {
        require 'iconv'
        converter = Iconv.new('ISO-8859-15//IGNORE//TRANSLIT','UTF-8')
        send_data(converter.iconv(generate_xls(@tasks)),
          :filename => 'all_tasks.xls',
          :type => 'application/vnd.ms-excel')
      }
    end
  end

end

The Unicode curly quotes are transformed into standard quotes, and Excel is happy again!

Acknowledgements and references:

How to export data as CSV
Working with UTF-8 in PDF::Writer and Ruby on Rails
Iconv Ruby class