Pages

Ramblings of a Software Engineer

Oct 5, 2010

Pattern Recognition - A Design Quiz!

After all that mess, finally India did put up a decent show at the CWG opening ceremony! With that positive note, let me turn this time to a more technical topic – software design.

Often I come across a strange phenomenon when I do technical interviews. If I name a design pattern and ask the candidates to explain about it, they come up with fairly good explanation, if they know about it. But if I give a scenario and ask them to come up with a design, they often tend to ignore patterns and come up with a design which just satisfies the functionality. This shows that there is some disconnect. Disconnect between theory and practice. This is not really strange, if you realize that any article or blog on Design Patterns usually starts with describing the pattern, and then describes various classes in the pattern and then how you implement the pattern in Java or C-Sharp or C++. There might be a text book example added to it. However, for a good designer, it is not enough to know about design patterns and how to implement them. A good designer should have the ability of identifying patterns suitable for a given scenario. In fact the pattern he or she comes up with need not be something which exactly matches the text book definition of an existing pattern. Like in art, improvisations are always welcome. After all software designing is also an art in some sense!

With this brief intro, let me try to do what I said above. I want to introduce a design pattern without actually telling what it is.

Here is the requirement. You are building a Rich Text Editor. It has the usual functions of a rich text editor like - typing text, copy, paste, making some text to bold, changing color, font etc. Let us say you need to develop a functionality of Undo and Redo for these functions. How do you design your Undo/Redo module?

Here is one approach. Create a class called Undo which has one method each for each operation, like undoType, undoPaste, undoBold etc. For each operation, the details of the data modified by the operation are stored in different data objects. Let us say typed in text is stored in a TypedText object, pasted text is stored in a PastedText object, bolded text is stored in BoldedText object etc. Each method in Undo class, takes a text editor object and the corresponding data object as parameters. The logic of undoing is implemented in each of that method.
How do we invoke the method in Undo class? Create an UndoListener class which listens for undo event. Ok. How does it know what is the operation that needs to be undone? We need to store the latest operation that is done. Since we would also want to support multiple undos, we need to store all the operations along with their order. So we store the operations with their order in a data structure. Whenever user performs an operation, the corresponding listener associated with that operation will create the corresponding data object (like PastedText, BoldedText etc.) and updates the operations list. UndoListner gets the latest operation from the list, checks what is the type of operation and based on the operation type, it calls corresponding method of Undo class.

The class diagram for the above design looks like this:



So what is the problem with this design? The required functionality is surely achieved. Are there any other issues with the design? If there are some problems with this, how can we overcome them?
Give a thought about it and I’ll discuss it further in my next post.

Sep 27, 2010

CWG 2010 - A Typical Software Project!

It is rather unfortunate that I have to start the blog with this post. But what to do, this is something that’s pestering me a lot currently!

While a common Indian might be wondering what the hell is going on with CWG, I guess its not too surprising to people like you and me in the Indian Software Industry. This kind of situation is not at all new to us, right! We would have seen many such CWG’s in our day to day work, only the scale is slightly different.

If we carefully look at it, right from the bidding process, we find so many similarities in CWG 2010 with our own Software Project that I begin to wonder if any of our IT giants are involved in this planning and execution! :-) It seems that India has won the bidding for CWG primarily based on its lucrative bid! Very typical... It has also made some extra gratis offers which are not really essential to the games! Again very much similar to our response to an RFP!

We had the first escalation from the customer (in this case CWG Federation President) more than a year before the commencement of the games! Are we not used to such customer escalations? What do we do? The higher management makes a bit of a noise and the manager will convince him that they are only "minor" slippages and can be easily corrected during the course of the project. That is it! And the project remains in the "green" state till it comes closer to the delivery date. Correct! Exactly the same thing happened with CWG. At the tail-end of the project, the status suddenly turns "red" and the team goes into a fire-fighting mode! Higher Management suddenly starts panicking and tries to do whatever is possible to deliver the application. And what happens? The quality gets hit! We get more and more escalations from the client. Then begins the blame game! Senior Manager blames the manager and he blames his lead or the recruitment department. Don't you see the same exact sequence of things happening in case of our CWG?!

If this is not enough to convince you of the similarities, here is more. Rains have greatly affected the arrangements and added to the woes. This is typical too. Its a good example for the failure of risk management. Aren't we not aware that this is a rainy season and we might have downpour in this season?

And then, we give various reasons to convince our management that the bugs are not really bugs. One of the most common reason is "Requirements mismatch" or "Standards mismatch"! A CWG official has given the same exact reason; our standards of cleanliness are different from that of the foreign countries. Are we not supposed to know what those standards are, in the first place!

And we are too familiar to the over-shooting of estimates and cost of the projects, don't we. Do you know what the cost over-shoot of CWG is? It is over 1600% (as of now). Can you believe it?!

We can always say and rest in peace that all this is a hype and false propaganda created by rest of the world to bring bad name to India. But its just like saying all the customers are irrational!

Such a ridiculously close similarity between the CWG and our own Software Projects, though a bit surprising, is very disturbing. This clearly shows that there is something going very wrong across various sections of our society. It is not the talent, in my opinion, that we lack. We have plenty of it. It’s the "professionalism" which seems to be lacking everywhere - determination to achieve something in a neat and clean way by doing it right at every step. That is what, I think, is the root cause of all this mess that we again and again encounter in our day to day work and everywhere else.

So, let us wake ourselves up. Wake up India, please!