Flickr Badge

Tuesday, May 30, 2006

Lightbox feature

I've added a cool new lightbox feature to this blog. Rather than explain it, it's a lot easier to demonstrate. In order for the lightbox feature to work, you have to click on the image on the website, as it uses Javascript which does not get loaded when viewing through an RSS reader.

To see it in action, just click on any of the images posted to the blog and see what happens.

If you like it, you can get the code from here.


Sunset at the chinese garden

Sunset at the chinese garden
Originally uploaded by Siddhi.

Friday, May 26, 2006

NTFS Junction

One of my gripes with Windows XP has been the lack of proper symlinks. They have shortcuts, but a shortcut is not a symlink. Try this:
  1. Create a shortcut to C:\WINDOWS and place the shortcut in C:\
  2. Rename the shortcut to "mytemp"
  3. Open the command prompt by doing Start->Run..->cmd and type cd C:\mytemp
If try that, you will find that you cant access the directory. This is because a shortcut doesn't create a link exactly, but creates a file mytemp.lnk. Now try cd C:\mytemp.lnk, and it will find the file, but since it is only an ordinary file, you can't do a change directory to it. In other words, a shortcut is nothing but a file which has special meaning only to Windows Explorer.

Well, it turns out that NTFS does support actual proper symlinks. These are called Junctions in NTFS. Junctions also allow you to mount filesystems at a mount point much like how it is done in UNIX. The only problem is that there is no way to create Junctions with Windows XP. That was until I found this awesome utility which allows you to create proper junctions on your NTFS drive. This is something that I have been wanting for ages. If you ever wanted proper symlinks on windows, you just have to check out Junction .

Monday, May 22, 2006

Recursion Part 6: References and Further Information

The following is a part of a series of articles I had written on recursion.

This, the final part of the series contains sources for the articles and where to get further information.

All Parts:

Recursion Part 1: Introduction to recursion
Recursion Part 2: Tail recursion, Accumulators and Iteration
Recursion Part 3: Exercises in tail recursion
Recursion Part 4: Tree Recursion and Dynamic Programming
Recursion Part 5: Structural and Generative Recursion
Recursion Part 6: References and Further Information

The best way to learn about recursion is to learn a language that doesn't support iteration. Scheme is a good language to learn in this context. A Scheme interpreter can be got from here

Another good resource is the 6.001 course from MIT. The course material for this course is available for free.

Two highly recommended books:
1. Structure and Interpretation of Computer Programs (also called as The Wizard Book). There is an Indian edition, but not very easy to find.
2. How to design programs. This book is also available in an Indian Edition, but there is often not much stock.

Both books use the Scheme language, so they also serve the purpose of those trying to learn Scheme. Both books are also available for free on the Internet.

For more on dynamic programming, see Chapter 15 of the book 'Introduction to Algorithms' by Cormen, Leiserson and Rivest. This is a college textbook and is available in any bookstore. Most other books on algorithms also include a chapter on dynamic programming. Otherwise searching Google for "dynamic programming" will provide lots of articles on this topic.

Any questions? Comments? Please leave a comment using the comment form below.

This post is a part of the selected archive.

Recursion Part 5: Structural and Generative Recursion

The following is a part of a series of articles I had written on recursion.

This part deals with two areas for which recursion is commonly applied. The first, called structural recursion, is used to traverse through different parts of a data structure, processing each part in some way. The second, called generative recursion, is used when we want to divide a problem into smaller subproblems, which are then solved.

All Parts:

Recursion Part 1: Introduction to recursion
Recursion Part 2: Tail recursion, Accumulators and Iteration
Recursion Part 3: Exercises in tail recursion
Recursion Part 4: Tree Recursion and Dynamic Programming
Recursion Part 5: Structural and Generative Recursion
Recursion Part 6: References and Further Information

Let us start of with structural recursion. Here is an example, an inorder traversal of a binary tree:

void inorder(node element)
if (NULL == element) {

This is a classic case of structural recursion. Each recursive call processes a part of the binary tree. Put together, we process all the elements in the tree. Structural recursion is often used when dealing with self-referential data structures like lists, trees and graphs. Functions to deal with these structures are hard to implement with iteration1, and even if we do manage to implement them with iteration, the resultant code is often very difficult to understand. Such code is best left as recursive.

In some cases, it is possible to modify the data structure itself so that common operations can be implemented iteratively. An example of this is the threaded tree data structure that modifies the classic binary tree to allow for iterative traversal.

In any case, except for exceptional cases, it is best to use recursive algorithms to implement structural recursion

Generative recursion is often used when we want to break up a problem into similar subproblems. The subproblems are solved and the results combined to get the final solution. Solving the subproblems in turn requires recursion to break the problem into smaller subproblems, and so on until we reach a trivial case. The recursive examples of factorial and fibonacci number calculations and the well known quicksort are examples of generative recursion.

Look at this fibonacci program again and convince yourself that it uses generative recursion:

int fibonacci(int n)
if (0 == n) {
return 0;
} else if (1 == n) {
return 1;
} else {
return fibonacci(n - 2) + fibonacci(n - 1);

Generative recursion that operates on a known finite set (eg: fibonacci(n) operates on integers between 0 and n) are good candidates for a dynamic programming approach. Generative recursion that operates on large or unknown sets (eg: functions that work with real numbers often fall into this category) are usually not condusive to dynamic programming. Some cases of generative recursion may have good iterative solutions, but this has to be considered on a case by case basis. In most cases, it is best to just leave them recursive.

Of course, all the above only applies to tree recursion. Tail recursion, whether structural or generative can always be converted into iteration.

1 The exception is linked lists. Linked lists usually result in tail recursion which can be converted to iteration.

Any questions? Comments? Please leave a comment using the comment form below.

This post is a part of the selected archive.

Sunday, May 21, 2006

Wednesday, May 17, 2006

Agile is not XP

I recently heard this podcast with Dave Thomas. Dave has talked on many occasions about the Dreyfus model of Skill Acquisition, which is similar to Shu Ha Ri. He also talks in the podcast about some Agile practitioners being dogmatic in their views. So in a sense, listening to the padcast made me go and write these posts, something that I've been meaning to do for a long time anyway.

In a previous post I had said "Sometimes I think that the term Agile has been co-opted by the XP and Scrum groups, but that's a topic for another post."

What is agile development? In theory, agile processes follow the four points of the agile manifesto. However, most people use the term "agile" to actually refer to either XP or Scrum, and consequently practices from these processes are invariably attached to the term "agile". This is a pity, because agile is a general term that refers to a host of different methodologies, many of which differ very markedly from XP.

For instance, while XP says no big design up front, both FDD and DSDM have distinct modelling phases at the start of a project. Similarly, XP minimises documentation, whereas say Crystal Clear does emphasise certain documentation. This obviously irritates a lot of people. Alsitair has an AgileIsntXp page on his twiki.

I also agree with Dave's comment that agilists can sometimes be dogmatic. How many times have we seen arguments along the lines of "thats big design up front, so its not agile", never mind if it helped solve the problem or not. I was just searching around for more info on the No Fluff Just Stuff conference when I came across this link which just illustrates the point (see section on Pragmatic Tracer Bullets).

If you are having a big discussion on the level of "is this big design up front or not?" then it's a lost cause already, because that is the wrong question. The question should be "will it help me produce working software?" and if the answer is yes, then you do it. Of course, as we saw in the Shu Ha Ri post, beginners who are just starting out with the process need clear rules, and "no big design up front" is a clear rule, whereas "will it help me produce working software" is not so easy to answer. You need to be in the Ha or Ri phase to answer this one.

There is a fundamental paradox here, because agile was developed in response to the "rules" based ISO/CMMI processes, replacing them with a more intuitive understanding of project management as placed out in the agile manifesto. This is great for the intermediate and expert project managers, what about those just starting out on the process who need clear rules? We need to put in certain rules and best practices to help beginners. But in the end, guiding beginners is all the rules are for. They are not "best practices" to be followed by everyone in every situation.

Finally, go read James Bach's posts on What is agile methodology? and No Best Practices, both of which hit the nail squarely on the head.

This post is a part of the selected archive.

Tuesday, May 16, 2006

Shu Ha Ri

Shu Ha Ri.

What is Shu Ha Ri?

Shu Ha Ri is a Japanese term, usually applied to martial arts training, to describe the stages in learning a skill. The first word, "Shu", means "to obey". The second word, "Ha", means "to break free". The third word, "Ri", means "to depart".

These three words describe the three stages of learning. When you are a novice, just starting out on a new skill, you need clear, precise, unambiguous instructions. You do not understand the bigger picture or the intent for the instructions. Any further background only confuses you. You are at the "Shu" stage - "to obey". After a while, you begin to learn the instructions, and the question that comes up is "why?". Why am I following these rules this way? What is the intent behind them? You slowly start to understand the context behind these rules. At this point, you have broken free of the rules. You are at the "Ha" stage - "to break free". Finally, you become an expert. You not only know the rules and the reasons, but you are in a position to create your own rules. You no longer follow the old rules, but follow your rules, crafted by you, just for you. You are at the "Ri" stage - "to depart".

In a fascinating experiment, expert airline pilots were asked to prepare rules for novice pilots. The novice pilots followed the rules and had no problems with them. However, when the expert pilots were then asked to follow their own rules, they found that their performance fell sharply. This is because expert pilots do not usually fly planes the way described in the rules. Expert pilots rely a lot on experience and intuition and often break the very rules that they had prescribed. They use contextual decision making and rules leave very little room for this type of decision making. However, had novice pilots been asked to perform without the rules, they would not have been able to, because they lacked the experience and intuition. Rules are critical for novice pilots to fly a plane. That is Shu Ha Ri. What is good for the expert is often not so good for the novice and vice-versa.

This principle is particularly applicable to process, or software development process to be more precise, although it is equally applicable to any organizational process. The great big battle about whether we need processes or not is missing the point completely. Everyone follows a process in their head. Even no process is a process. The question is whether to follow a predefined process or an ad-hoc process where you just do whatever you are thinking of at that moment.

Let us apply the Shu-Ha-Ri principle at this point. Are you a novice at managing projects? In that case you need a clear, unambiguous process. If you have been in multiple project, then you need a less defined process, or apply your own process if you are an expert at project management. These leave room for the contextual decision making we talked about earlier. However, the reverse will simply not work. Leaving novices without a process, or imposing a rigid process on an expert are both doomed to fail right from the start.

So the point to take away from this is that the way novices and experts perform the same task is very different, and the guidance that they require is also very different. For all those grappling with the process question, think back again to Shu Ha Ri and see how it can help you.

See also: Dreyfus model of Skill Acquisition

This post is a part of the selected archive.

Sunday, May 14, 2006

Flower with raindrops

Originally uploaded by Siddhi.
Took this photo yesterday at the Singapore Botanical Gardens. It had just finished raining when I took this shot with the raindrops still on the petals.

Thursday, May 11, 2006

Opera targetting new devices

Opera has slowly moved from writing browsers for mobile phones to writing browsers for every sort of device. A few months ago, Opera announced a browser for the Nintendo DS, a handheld video game platform. Yesterday, Opera announced support for the Opera browser on Nintendo's upcoming Nintendo Wii console. To quote Eskil Sivertsen:

"More and more devices are featuring the Opera browser. From PCs to mobile phones, in-flight entertainment systems, media players and game consols. The browser is becoming a central application on these devices, bringing truth to our mission of offering the best Internet experience on any device."

Sunday, May 07, 2006

Holy cow

[via Manu] When I read this, I was like.. Holy Cow! A guy who caught the Assistant Commissioner of Police (!!) run a red light.

I caught up with him a few hundred metres later, and pulled up beside the officer’s window. I looked in, and I caught his eye. I asked him (quite politely, I may add) what a guy like me is expected to do when I see an officer in uniform, on duty, violate a rule the way he just did. From his reaction, I judge that no one had ever asked him this question earlier.