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.
Showing posts with label coding. Show all posts
Showing posts with label coding. Show all posts
Monday, April 16, 2007
Lesson -1
Labels:
coding
Subscribe to:
Posts (Atom)