Author Archives: Stefan Siebel

Natural Project Planning

Allen’s Getting Things Done is a resourceful book in many ways. If someone asked me for the two most valuable / interesting passages of the booking I’d probably point out the “Getting Things Done” diagram which I wrote about here and the “Natural Project Planning” which I want to write about in this post.

Natural Project Planning consists out of five steps:

  1. Defining purpose and principles
  2. Outcome visioning
  3. Brainstorming
  4. Organizing
  5. Identifying next actions

If you’re like me you will probably read over that list and think “yep, that’s how it should be, so what’s the big deal here”. Well, the big deal is, that while this model is very natural it won’t be followed most of the time.

Think back to your last kick start meeting for the latest and greatest project. For sure someone said “let’s brainstorm”. That just sounds right and very actionable. The problem: If you didn’t talk about the purpose of the new project yet and if you have no idea about possible desired outcomes for the project the brainstorming will lead to absolutely nothing constructive. Without knowing the purpose of the project and without any vision you won’t be able to separate the good ideas from the bad ones. So next time someone says “Let’s brainstorm” make sure everybody is clear about the purpose, principles and outcome visions.

Once these are defined and you successfully brainstormed the new project everybody leaves the room and now what? If you’re lucky someone took a photo of the whiteboard with all the good and bad results of the brainstorming on it. Since most teams don’t have the luxury of working on one project at a time it is fairly certain that other things come up and get prioritized. After a week nobody will understand anymore what all the words on the photo of the whiteboard are really about and we have to start the process all over again.
Brainstorming is important but it will be for nothing if you don’t take the time and organize all the unordered ideas into actionable items. Start writing a project plan. I doesn’t have to be a huge formal document. Simply make a list of “next actions”. Prioritize them and assign them to concrete people.

Following these five easy steps helps to get projects started and keep them going. It works for small and big projects, however for big projects you’ll likely need more formal approaches…

DeliciousTwitterFacebookLinkedInRedditSlashdotTechnorati FavoritesDiggShare
Posted in Business | Leave a comment

Improving the speed of Ajax GET requests

In my last article I described how to improve the speed of your Rails 3 Ajax Application by returning correct HTTP states and optimizing browser caching.

One thing that still annoyed me was the fact that the browser had to wait for the 304 “Not Modified” response from the server before displaying cached data. Once the response was received it would trigger the success callback. That means the user needs to wait for a response from the server just so that the browser can display cached data…
At that point I remembered reading about Wycats’ jquery-offline. jQuery-Offline has the same interface as jQuery’s native getJSON, but once it receives the response it’ll store the JSON data in the browser’s localStorage. The next time the same Ajax request is triggered the success callback is executed twice. First when the data is loaded from the localStorage (which is very very fast obviously) and the second time when the browser returns a 200 status response. The great thing is, that the success callback won’t be triggered if the server returns a 304 “Not Modified” status code. This is really really neat and makes the UI unbelievably snappy.

jQuery.retrieveJSON( "/lists/1", { options: "in case you need it" }, function( data, textStatus, jqXhr) {
  // process the data. This will be called up to two times.
} );

Unfortunately getJSON doesn’t have a great way to handle errors. Since retrieveJSON uses the same interface it suffers from the same weakness. Luckily jQuery 1.5 introduced the jqXHR object. With jqXHR error handling becomes real easy:

var jqXhr = jQuery.retrieveJSON( "/lists/1", { options: "in case you need it" }, function( data, textStatus, jqXhr) {
  // process the data. This will be called up to two times.
} );
jqXhr.error( function( xhr, errorType, exception ) {
  // do your error handling here.
} );

If you want to use above functionality you need to use my fork of jQuery-Offline because the official version hasn’t been updated yet to return a jqXhr object.

DeliciousTwitterFacebookLinkedInRedditSlashdotTechnorati FavoritesDiggShare
Posted in jQuery | Leave a comment

Das Weltgeheimnis – Thomas De Padova

Das Weltgeheimnis by Thomas De Padova is not quite an international best seller, at least I didn’t find an English version of the book. Nevertheless for those who speak German and who are interested in natural science it is a very enjoyable book.

De Padova tells the story of Galileo Galilei and Johannes Kepler, two remarkable figures of history who changed how we saw the world and the universe in which we live.

Kepler lived and worked many years in Prague, back then the centre of the Habsburg Monarchy. With endless patience Kepler analysed Tycho Brahe‘s observations of stars and planets and thus found the Laws of Planetary Motion.

Galileo Galilei is most famous for the heliocentric model. Though he wasn’t the first one proposing a model in which the sun, not the earth, is the centre of our planetary system he and Kepler were two important personalities arguing for the model.

Among many interesting things, there are three things I’d like to point out here.

First, it’s amazing under which conditions and with which persistence scientists and philosophers in the 17th century changed the world. They started a process which would accelerate through the 18th, 19th and 20th century until the present day (and it is still accelerating).

Second, many chapters about Kepler give a little bit of inside into how life must have been in Prague in the 17th century. It was the capital of the Habsburg Monarchy and thus for a huge part of what we call Europe today the centre of the world. Two world wars and 40 years of communism change things a lot…

Third, in the story of Kepler and Galileo you recognize all to well the principle of “the adjacent possible” described in Steven Johnson’s awesome book “Where good ideas come from“. Galileo and Kepler both were able to build on top of Copernicus. Kepler based his analysis and calculations on Brahe’s extensive data collection. One generation later, Isaac Newton referred to Galilei’s and Kepler’s findings…

The history of science is an exciting story to tell and Thomas De Padova tells it well.

If you are interested in science books: I’m currently reading “A Short History of Nearly Everything” by Bill Bryson. I’m not yet finished with it, but Bryson is a brilliant narrator and I highly recommend to get a copy (of the book, not Bryson…).

DeliciousTwitterFacebookLinkedInRedditSlashdotTechnorati FavoritesDiggShare
Posted in Books | Leave a comment

Rails 3: Improving the speed of your Ajax Application

List Kung Fu uses Ajax a lot and so far it works out pretty well. Over the past two weeks I’ve looked into improving the performance of the UI and there are a couple of things that helped a lot and which I want to share here.

Returning the correct HTTP status code and optimize browser caching

There are two status codes I mean specifically:

  • 200 – “Ok“. Tells the browser that the server was able to respond successfully to the request. The response contains the data from the server in the HTTP payload.
  • 304 – “Not modified“. Tells the browser that the data for the sent request did not change and that data should be loaded from the cache. In this case the response does not contain any payload.

Since a “Not Modified”-message contains much less data (no content, only header) that’s what you preferably want to return to the browser. Of cause you only want to that if you are sure that the browser already has the data.

For my application I found that the server was returning far more often 200-responses than 304-responses which caused

  • More data than necessary had to be transmitted.
  • More data had to be processed by the UI.

Both things were slowing down the application. Just a little, but enough to be noticed in the UI. Luckily there are only a few things you need to change in your Rails application to get the right behaviour.

1) Use stale? in your GET methods

  def show
    @list_item = @list.list_items.find( params[ :id ] )
    if stale?( :etag => @list_item, :last_modified => @list_item.updated_at.utc, :public => true )
      respond_with( @list_item )
    end
  end

Stale? sends back an etag and a last_modified date in the response. With the next request to the same URL the browser will send this etag and last_modified date to the server. The stale? method then analyses both parameters and returns 304 in case they are the same or 200 plus the new content if the newly calculated values are different.

More information on stale? you get in Rails’ API documentation and on Rails Guides.

2) Make sure the browser asks for new data on each request

After above modifications something interesting was happening. If the same Ajax action was triggered multiple times within a short period of time, the browser wouldn’t send a request at all to the server, but instead take the data from the cache. While obviously this made the UI really fast, it wasn’t exactly what I wanted. My goal was maximum performance while guaranteeing correct and up to date data on the screen.
The browser’s caching behaviour is influenced by three HTTP header flags: cache-controll, pragma and expires.

To “disable” caching in the browser all together you could send the following:

  def set_cache_buster
    response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
    response.headers["Pragma"] = "no-cache"
    response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
  end

What I wanted however is this:

  def set_must_revalidate
    response.headers["Cache-Control"] = "must-revalidate"
  end

This advices the browser to check for new / updated data with each request. I added this method to my application_controller.rb and I’m calling it in a before_filter of controllers for which I want to have this flag set.

3) Using stale? for GET methods which return collections (e.g. index)

Above stale? example is taken from a controller’s show method. This is what you find in most examples on the web. To make this work in a method which returns a collection, like typically a controller’s index method you need to find some way to figure out whether the current collection is the same as it was for the last request.
List Kung Fu has a model List which has_many ListItems. Each ListItem belongs_to a List. To be able to determine in list_items_controller whether a collection of ListItems changed, I added code which updates the list.updated_at timestamp for each write operation on a list_item.

In ListItem.rb:

class ListItem < ActiveRecord::Base
  belongs_to :list
  after_save :update_list
  after_destroy :update_list
 
  # [...]
 
  def update_list
    self.list.updated_at = Time.now
    self.list.save
  end
end

Thus, in the list_items_controller the index method could look like this:

  def index
    @list_items = @list.list_items
 
    if stale?( :last_modified => @list.updated_at )
      respond_with( @list_items )
    end
  end

Instead of using the updated_at field I could have added a version field to the List model, but that seemed unnecessary. If the model doesn't have a model it belongs_to, you need to find another strategy for checking whether the collection has been modified. Maybe it's possible to calculate a checksum over all objects in the collection...

So much for this post. I also switched from using jQuery's getJSON to Wycats jquery-offline. More about that in my next post.

DeliciousTwitterFacebookLinkedInRedditSlashdotTechnorati FavoritesDiggShare
Posted in RubyOnRails | 2 Comments

Persepolis – Marjane Satrapi

Persepolis is an amazing comic book and it offers a view on Iran and life in Iran that you don’t hear about often these days. I read it within a couple of days and it is very worthwhile. It will make you reconsider your own situation and history.

They also made a movie out of it. I haven’t seen it but it got lots of positive reviews on Amazon:

DeliciousTwitterFacebookLinkedInRedditSlashdotTechnorati FavoritesDiggShare
Posted in Books | Leave a comment