Most of the programmers while coding don’t pay attention to some basic principles like properly naming the variable, commenting , exception handling. During my experience of development, spending some time, and designing your code, saves you from lots of trouble later. When you are doing some bug fixing. Or some one else is making some changes or enhancement to your code. Here are some tips you can use to avoid common code writing issues.
- Meaningful Names for Variables and Controls
- Comment your code
Give names that are meaningful, instead of int i=0; use int totalStudents =0; This helps you in future when you are reviewing your code and you know instantly what is going around.
Yeas most of do this, but do we do it right way? Follow the following guideline for commenting next time.
-
- A few sentences before the procedure/function saying what it does.
- A description of the values being passed into it.
- If a function, a description of what it returns.
- Inside the procedure/function, comments that split the code up into shorter tasks.
- For chunks of code that seem thorny, a quick explanation of what is happening.
- Exception/Error Handling
- Use Constants instead of hard coding values
- Use some coding Standard
Good error checking makes it faster to debug too. This saves tons of time, and it bears repeating. Time is the most valuable resource we have.
The overall objective is simple: write code so that, if someone who has no idea what it’s doing reads it, he or she can understand what’s going on as quickly as possible. So avoid hard coding numbers in code instead make a central place for all such constants and use it in every where in your code.
Follow some standard conventions for coding. for example java conventions
- I hope these tips will help you in future to code efficiently in future.
nice piece of information….
Comment by soorya — February 10, 2009 @ 11:59 am