Monday Sep 03, 2007

Test Driven Design

People may have heard about Test Driven Development, but I just reaped the full benefits of introducing test cases during design itself, but in a sligtly different way.

Assume that you are developing a module and have completed some form of pseudo-code for it and it worked fine (like the way it worked for me). Then coding starts and the cycle goes like this.

Develop code according to the design specs -> Write unit tests, test rigorously -> Release the code -> Apply Patches as and when necessary.

But when you start writing test cases during design phase, it simplifies things so much that one never needs to undergo the pain of fixing several hard to determine bugs and modify the code (which makes it worse of course). Last week when I was developing a pseudo code for my module, it worked fine, but after introducing some 15 - 20 test cases this is what I experienced.

Test case              Result                   Action          

Test case 1             PASS                     N/A
Test case 2             FAIL                   Added an if condition in the pseudo code
Test case 2             PASS                     N/A
Test case 3             FAIL                   Failed to handle exception in code, therefore added exception handling
Test case 3             PASS                      N/A
Test case 4             FAIL                   Introduced a new method to handle this functionality
Test case 4             PASS                      N/A   
Test case 5             FAIL                  Added a check to sanitize the input
Test case 20          PASS  

All tests Passed finally.

Now after this phase, when I looked back my initial pseudo-code and the way it has changed after all these tests passed, there were lot of differences in my pseudo-code in terms of readability, robustness, security, etc (add other qualities of good code). BTW each time I did a code walkthrough to make sure my tests passed.

How did this approach made the difference? When I did the actual coding, things worked fine the FIRST time the module was executed and I just ensured that all the tests passed during execution without any major changes in code (of course there were minor issues, but those were due to coding errors and not due to design).

Now assume the case when these tests were not there during the design phase. Probably there would have been 15 - 20 patches which may have incurred painful changes to code each time, at the worst would have killed several hours of productive time.

Therefore, sooner the test cases are introduced, the better the life will be for developers and all it requires is some extra hours spent during design, thinking from an end user's perspective.

Thursday May 31, 2007

Creativity and Technology

I had this doubt on which way to go, to become a technology expert and solve problems or develop problem solving ability at the first place, then focus on technology for implementation models. But people respect great thinkers and those with creative skills irrespective of their technical accomplishments and I realized why they are right.

Even in one of the hoardings displayed by Sun in Bangalore for recruiting great engineers it was mentioned

"Thinkers needed to work with James Gosling"
and not
"Experts needed to work with James Gosling"

Ok, to the next question, How to develop creative thinking skills? Probably this small tip may help.

As the saying goes Great people don't do different things but they do things differently, consider the example of Larry Page and Sergey Brin, at a stage where no one realized how search can influence people and it was considered a boring problem, Larry and Sergey made the difference and the rest is history. Therefore the first step towards creativity is to focus on a problem where we think we can make a difference.

But one can only succeed if they stick to the problem till the end. This is where most people gets lost and this separates the winners from the rest.

But from my experience, to be creative, one need not start tackling mind-boggling problems, but if we show difference in the little things we do, that will definitely propel our creative thinking to a level we would have never imagined! The best thing is Creativity can never be replaced by Technology.

Wednesday May 30, 2007

The problem in Software testing

The easiest part is writing a piece of code, the toughest part as obvious is testing it. Code in a day and it takes the rest of life to test it. There are no limits in testing an enterprise software as it starts with sanity tests, followed by black box testing, white box testing, regression testing, load testing, performance testing, I don't want to write the rest, please visit here .

The question is will any software truly pass these tests as and when applicable or is there a proper process and procedure to carry out these tests. The obvious answer if NO. The reason why all these tests are never carried out is that it will so badly expose the serious flaws in the software and as we dig deep into testing, we can only get hands dirty similar to digging deep in a soil. And as a result no product can ever be released successfully in time (it's a fact).

But what can be done systematically to overcome these so called bugs? The easiest way is to make them as Known issues in case the bug is so complex, therefore fixing it may cause a break in functionality. The second simple way is called Hot fix, in which you simply comment that part of the code. But these things don't solve the issue in first place. They say prevention is better than cure. Therefore one needs to prevent bugs right from day one. With techniques like Test first development coming to the rescue of developers, the question is whether these techniques are followed during development in these days where a product has hard and fast deadline? Again the simple answer is it's often not possible.

Therefore the best solution as far as bugs are concerned is fix bugs for sometime and call it a day. Then take the bugs as and when it comes in the form of escalations and update the software with a clearly documented list of fixed bugs , because after a period of time, bugs has to come to us and it's nearly impossible for the us to go behind identifying it.

Thursday Apr 26, 2007

Swing: The problem with JFrame.toFront

I was trying to make a JFrame active after it was minimized. The code snippet is as follows

JFrame frame = new JFrame(.....);
if (frame.isVisible() == true)

The above code works, but fails to make the frame active and one needs to click the frame window again to make it active. There were other alternatives like

frame.requestFocus() and frame.requestFocusInWwindow(), but they didn't produce the desired results I expected. I am not sure about the sequence of APIs which would accomplish the task.

Interestingly, there were lot of discussions about the behavior of JFrame.toFront() , but the question is can we make a minimized JFrame active.

Tuesday Apr 17, 2007

Python: Method overriding, How?

I have read Mark Pilgrim's Dive into Python several times, but this explanation on method overriding by Guido still puzzles me.

Guido, the original author of Python, explains method overriding this way: "Derived classes may override methods of their base classes. Because methods have no special privileges when calling other methods of the same object, a method of a base class that calls another method defined in the same base class, may in fact end up calling a method of a derived class that overrides it. (For C++ programmers: all methods in Python are effectively virtual.)" If that doesn't make sense to you (it confuses the hell out of me), feel free to ignore it. I just thought I'd pass it along.

Although I can interpret the statement, I still want to know HOW?

Saturday Apr 14, 2007

My home page and my other blog

If somebody wants to check my stuff, please visit my home page The contents in it are not updated regularly, but they may definitely be useful. Long before I hosted my page in a free shell, but paid the price for not paying! When it was well ranked by Google and had good hits, the service disappeared. The moral is if you want to share useful content, you should pay :) BTW is my first appearance to blogging world? Not really.



« July 2016