Web Programming: 10 Coding Tips
Summary : It is not enough for a web developer to have mastered a programming language. To be of value, code must be usable, legible, organized and logical.
It is not enough for a web developer to have mastered a programming language. To be of value, code must be usable, legible, organized and logical. There are coding guidelines which every developer should follow to produce a quality coding styles. These guidelines apply to any programming language; C, C++, Java, C Sharp, Visual Basic, PHP, etc. :
- Avoid using the same variable again and again for different purposes. Many web developers believe memory will be wasted if a separate variable is declared for each purpose. If any debugging is to be done, however, reusing variables for different purposes can be confusing to the debugger, and your dry-run may not work properly. So, if your program is small, however, then you can use the same variable. Otherwise, if it is complex, do not use this practice.
- Capitalize the names of global variables. To avoid confusion and possible errors, use capital letters to indicate a distinguishable difference between a local and global variable. This helps to avoid any confusion during the dry run or debugging stages.
- Declare all variables in one place. This helps the programmer to analyze whether some variable is yet declared or not. If developers declare variables at different locations, it is more difficult to keep track of them. The variables should normally defined just below the function declaration for consistency's sake.
- Use proper indentation throughout the whole program. Indenting simplifies understanding and following code as well as identifying the logic behind the statements. Writing functions, iterations and conditional statements without indenting indicates lax coding skills, and it looks like a junk also. There should be a proper demarkation in your mind the flow of which should appear throughout your code.
- Use commenting generously. Commenting is very important. Although the creating web developer may clearly see the link between their logic and programming, this is not the case for anyone else involved in the coding process. Once the program is debugged, or amendments made, it is tedious and time consuming to identify the logic behind an uncommented coding section.
- Do not use labels. In some programming languages like BASIC, there is wide variety of labels available. Experts say that using such labels produces extra burden in the operating system, however, so, they should be avoided.
- Do not declare unused functions or variables. This practice is also something to avoid. Declaring an unused variable can be confusing, especially since the information is irrelevant. It is a good idea to check for this during the dry-run also.
- Coupling should be avoided. Cohesion should be increased instead. Coupling occurs when the output of a function is input to another. This produces a sort of ripple effect, and debugging becomes problematic. Error-laden programming is typically created from coupling.
- Write the program or check the logic first. Typing out the code should be the final step. It is a common practice for web developers to jump on their system to code, build logic and make the necessary corrections in one step. Organizing development activities in this way may produce problems like unused variables (regular declaration and descarding), unused functions (declare and forget to call or just checking), or logic errors. It is a better idea to plan out the program first, then begin work on a computer.
- Develop your own logic. Each person has logic, but there should always be a flow to it. If flow is absent, then your ideas can not reach the destination. So, rather than always depending upon an old algorithm, try developing your own program based on your logic.
About the author : Som Dutt Tripathi is a IT professional who has worked with Visual Basic .NET and Visual Basic 6.0 and SQL Server.
|