Archive for July, 2008

No more comments in your code

Friday, July 25th, 2008

Comments, the more the better… right? Well I thought so too, in fact this is some of my code of a few days ago:

// handle the initialization of jobs
if (request.getParameter("initiateJobs") != null && request.getParameter("initiateJobs").equalsIgnoreCase("true")) {
	initializeJobs();
}

// get the trigger info, which will be displayed on the jsp page
List triggerInfo = getTriggerInfo();
request.setAttribute("triggerInfo", triggerInfo);

But what does it really add? Besides two lines of text. The code in the ‘if’ statement should be clear enough for a web programmer, and the method ‘initializeJobs’ tells as much as the comment. Same goes for the two lines of code below that. What would my intention be by putting ‘triggerInfo’ on the request scope? Point made.

Maybe you say ‘it’s faster to read’. Well… I don’t think it is.

if (request.getParameter("initiateJobs") != null && request.getParameter("initiateJobs").equalsIgnoreCase("true")) {
	initializeJobs();
}

List triggerInfo = getTriggerInfo();
request.setAttribute("triggerInfo", triggerInfo);

Looking at one of my last lines of code I realized Sammy Larbi and Jeff Atwood have a point.

Google exception humor

Thursday, July 17th, 2008

A few days ago I was trying to open my gmail on a rather unstable Wifi connection, it was loading… loading… and suddenly it showed an error page saying:

Dear valued user,

You have reached the error page for the error page…
You win!!

Pretty funny if you ask me. But what if I got this error while trying to access an application that is failing on me all the time?

I think I would find it at least very annoying. It made me realize every application of Google just works, all the time (well almost all the time). I blog this because I accidentally found the following very interesting page: highscalability.com.

It has some interesting posts on how google, amazon or youtube handle their high availability. Highly recommended reading. Some quotes:

YouTube

Some data are calculated and sent to each application so the values are cached in local memory. This is an underused strategy. The fastest cache is in your application server and it doesn’t take much time to send precalculated data to all your servers. Just have an agent that watches for changes, precalculates, and sends.

Google

Spanning multiple data centers is still an unsolved problem. Most websites are in one and at most two data centers. How to fully distribute a website across a set of data centers is, shall we say, tricky.

Use ultra cheap commodity hardware and build software on top to handle their death.

Amazon

You build it, you run it. This brings developers into contact with the day-to-day operation of their software. It also brings them into day-to-day contact with the customer. This customer feedback loop is essential for improving the quality of the service.

Embrace innovation. In front of the whole company, Jeff Bezos would give an old Nike shoe as “Just do it” award to those who innovated.