Code or not to Code…

June 5, 2007

How to Code Efficiently

Filed under: Coding — noshi316 @ 12:53 pm

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
  • 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.

  • Comment your code

Yeas most of do this, but do we do it right way? Follow the following guideline for commenting next time.

    1. A few sentences before the procedure/function saying what it does.
    2. A description of the values being passed into it.
    3. If a function, a description of what it returns.
    4. Inside the procedure/function, comments that split the code up into shorter tasks.
    5. For chunks of code that seem thorny, a quick explanation of what is happening.
  • Exception/Error Handling
  • 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.

  • Use Constants instead of hard coding values
  • 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.

  • Use some coding Standard
  • Follow some standard conventions for coding. for example java conventions

    I hope these tips will help you in future to code efficiently in future.

1 Comment »

  1. nice piece of information….

    Comment by soorya — February 10, 2009 @ 11:59 am


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.