Kontera

Tuesday, December 22, 2009

Good Programming Practices

Documentation

Comment your code such that it is clear what you code does. You should be able to figure out your code years after its written .A good programmer should be able to figure out what your code does from your comments.

Your code should be well formatted

 • Use Tabs to indent:
Use tabs to indent; don’t use spaces. The problem with the spaces is that nobody ever uses same number of spaces for indentation even with in the same file. Some people use two spaces, some use four spaces. Manually adding spaces is very difficult. So it is better to use tab instead of space.

• Add proper Comments
Comments are the most important part of your code. Add comment to your code in simple English. There are different types of comments;

     Comments put in page header













This will help to find who creates the page, when etc.

 o Comments the methods you write

  •  A description of what the procedure does
  • Type of arguments -> type of return value
  • Constraints that need to be satisfied by arguments (requires clause)
/**

* Gets value for permission
*
* @return the permission
*/
public int getPermission() {
return permission;
}

• Compound Statements must in a well structured form

































Use good naming conventions


Look at the program, did you understand anything? So it is better to use good naming conventions.



Use Global variables sparingly

Use global variables carefully otherwise it will damage your code.

Provide useful error messages

You should provide a user-friendly error message while simultaneously logging a programmer-friendly message with enough information that they can investigate the cause of the error.

Let's recap the general rules:

• Always use braces to delimit blocks, even—nay, especially—one-line blocks
• Use tabs (not spaces) for indenting
• Comment every block
• Comments that apply to a single line should go at the end of that line
• Try to end comments with periods (or other appropriate punctuation)
• Use braces around every block, even one-line blocks


















0 comments:

Post a Comment