Avoid these mistakes while writing code
by
, 14th February 2011 at 05:41 PM (13134 Views)
- Don’t write deeply nested code
It is bad programming style to write deeply nested code – the code has a tendency to drift across the page to the right and soon becomes unreadable. Try to limit most of your code to a maximum of two levels of indentation. This can be achieved by dividing the code into shorter functions.- Don’t write very large modules
A module should not contain more than 400 lines of source code. It is better to have several small modules than one large one.- Don’t write very long functions
Don’t write functions with more than 15 to 20 lines of code. Split large function into several smaller ones. Don’t solve the problem by writing long lines.- Don’t write very long lines
Don’t write very long lines. A line should not have more than 80 characters.
Example:
if(objHideRevealPalette.tree["paletteButton.textHideIcon"].getSelected() || objHideRevealPalette.tree["paletteButton.textRevealIcon"].getSelected())
Write above line like this:
var bHide:Boolean = objHideRevealPalette.tree["paletteButton.textHideIcon"].getSelected();
var bReveal:Boolean = objHideRevealPalette.tree["paletteButton.textRevealIcon"].getSelected();
if(bHide || bReveal)- Variable names
Choose meaningful variable names – this is very difficult.- Function names
The function name must agree exactly with what the function does. It should return the kind of arguments implied by the function name. It should not surprise the reader. Use conventional names for conventional functions- Format programs in a consistent manner
A consistent programming style will help you, and other people, to understand your code. Different people have different styles concerning indentation, usage of spaces etc.
For example you might like to write tuples with a single comma between the elements:
{12,23,45}
Other people might use a comma followed by a blank:
{12, 23, 45}
Once you have adopted style – stick to it.
Within a larger project, the same style should be used in all parts.
:ghz_01::tatice_06:
Comments
Trackbacks
Total Trackbacks 0