Sunday, February 17, 2008

The Issue with Equals Method

We all know that Equals method is synonymous with ==
So we can say
a.b.c.equals(obj) instead of a.b.c == obj
But we may run across some issues here
Lets say there is a chance that a.b can be null
So we can write the code as
If(a.b != null && a.b.c.Equals(obj))
This looks alright but what if a.b.c is null!!
So we can say:
If(a.b != null && a.b.c != null && a.b.c.Equals(obj)
Wait…………..
There is another simple way to write this!
If(a.b != null && a.b.c == obj)
This works even if a.b.c is null
So this means use Equals method only when you’ve overridden the method, in all other cases we can be happy with ==

Friday, February 1, 2008

Developer’s Attitude on Developer Testing

During my initial days in software industry I was working in a level 3 support project. Initially I was doing less development and a lot of peer testing, b’coz this is a big application and the lead thought that the best way to understand the application is through testing. During the initial year I was one of the best testers. I had the energy and enthusiasm to test for corner cases. But after 4 years in development I really don’t have the patience to do even unit testing!
So what has gone wrong?
Is this the right attitude?
Do all S/W developers face this problem?
I don’t know the correct answer but for me I’m pretty happy with what I’m doing.
When you are into development you’ll have this mentality that whatever I’ve coded should be working correctly, but you should do unit testing but never should do regression testing.
Testers are present for doing just that and also to nail down some corner cases…..if you’re going to do the same thing that they will do then you are just wasting your time.When I started development I was coding for 1 day and testing for 3 days J
I was very cautious; I don’t want my bug to be reopened. So I was termed as a person who does things effectively but take some time to do it.
My lead was not unhappy, but I was draining my energy. I was wasting my energy on something which would’ve been definitely done by testers!!


So what am I going to gain by being over cautious?
Me being over-cautious affects both me and the tester.
I would’ve spent my time effectively in solving some other bug
If I covered all the scenarios and gave to tester, the tester will be running all the scenarios once again and would’ve got bored.

We should make the testers life interesting J
Let them find bugs and be happy about that……We will fix it when it comes.
A developer should not have ego. He should know that he can be defeated all the time and should not worry about that.
His aim is to code better and test it in the shortest possible time and give the rest of the job to tester.
Even Jon Bentley had a bug, why can’t you?

How does Contains work in Generic List

We all know what contains mean for string operation, but there is a little ambiguity on what contains mean in a generic list.
Does it look for the correct item or does it look for all the Items which contains the entry.
Even though I know the answer intuitively I just thought lemme confirm that with a simple program.
The Program is as follows:
***************************************************************************************************
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication2
{
class Program
{
static void Main (string[] args)
{
List intList = new List();
intList.Add(100);
intList.Add(11);
intList.Add(111);
if(intList.Contains(1))
Console.WriteLine("one is present");
if(intList.Contains(11))
Console.WriteLine("11 is present");
if(intList.Contains(100))
Console.WriteLine("100 is present");
}
}
}
***************************************************************************************************
The output is :
11 is present
100 is present

So it looks for the *exact* Item