Monday, April 16, 2007

Lesson -1

Simple tips to follow for bug-free, easy maintainable code:

1. Never copy a single line in your code. Better use a method even it is just one line. (prone to bugs, if you don't follow)
For Example:
int value1 = obj.getValue1() > 10 ? 10 : obj.getValue1();
int value2 = obj.getValue2() > 10 ? 10 : obj.getValue2();

Better way of writing above code is:
int value1 = getActualValue(obj.getValue1());
int value2 = getActualValue(obj.getValue2());

int getActualValue(int value)
{
return value > 10 ? 10 : value;
}


2. Never hardcode anything. Always assign values to constants and use that in the place where you want to use those values. This makes life simpler, when you want to change that value in all locations wherever it is used. This is very simple to say. But many people don't follow it.


more to come soon.

4 comments:

friendz said...

so r u writing a book

Pallavi Palleti said...

I am not that great. But would like to, if I acquire that much knowledge. :)

friendz said...

Hi I read in Munjals blog that Riya is closing there operations in India. What abt do u gievn an option to go to US

Pallavi Palleti said...

Not yet decided.