Home arrow Development Cycles arrow Page 4 - Coding Standards

Coding Standards

According to the dictionary, "standard" stands for “something considered by an authority or by general consent as a basis of comparison; an approved model.” Now you may ask why we need to complicate our lives with the adoption of some coding standards. The answer to this question lies in the following pages.

Author Info:
By: Gabor Bernat
Rating: 5 stars5 stars5 stars5 stars5 stars / 9
March 05, 2008
  1. · Coding Standards
  2. · The Advantages and Disadvantages
  3. · A Taste of Standards
  4. · More About Standards
  5. · Conclusions

print this article

Coding Standards - More About Standards
(Page 4 of 5 )

Don't get into the habit of using "spaces" (if you do it by pressing the space bar) and the tab size should be set at 4. Leave a blank line for logically separating a code snippet. Single spaces will be present before and after the operator. Avoid writing long methods. None of your methods should be more than 100 lines (the screen size of your monitor). If it becomes longer, split it into another method.

When passing on the Object Oriented Programming [OOP] path, consider the following guideline: one file will hold only one class; the file name should be the class's name. Don't pass too many variables for a method; create a structure if you must. Also, avoid using method variables by address because if you modify a value, then in the final product you will spend hours searching for the place where you messed up. Instead, declare a local variable, assign the value you want to pass to the function to the freshly created name, and call the method for the local variable. The { } parentheses should always be put out, this way you can easily add any extra line that you forget to the loop later on. And as a final note, please do use constants instead of hard code.

The most valuable code is clearly comprehended by anyone. To achieve this, don't be afraid of commenting on your code and comment on it right as you write it. Don't fall prey to illusions. Nobody comments on his/her snippets after the fact; this will also help you create more logical code because you are explaining it and writing it simultaneously. Use // or ///, since /* */ isn't recommended. However, you only need the optimal amount of comments; don't start to waste a lot of time writing them. If you aren't implementing weird logic, then a couple of short words will do the trick. Great readability is achieved through good code and optimal content, so keep this in mind.

These few standards delivered in nutshell will help you realize the advantage of  clean and good code. And for a final proof, glance over at the code below. Both samples are the same code but programmed differently in a sort of non-standard, rebellious way. Can you see the difference?

The rebellious non-standard way of coding:

bool that(string a)



Bool i;

string res=nxy+"has been: "+"123";


if(res&&i){//the commands are

return false;}

return true;}

The code written with the standards in mind:

 bool ProcessBook(string name)


_bookTitle = "alfa" + name;

Bool IsTakenOut;


string result = _bookTitle + "has been: " + ID_LIBRARY; // previously defined const ID_LIBRARY



if( result && i )


//the commands are


return false;


return true;


blog comments powered by Disqus

- Division of Large Numbers
- Branch and Bound Algorithm Technique
- Dynamic Programming Algorithm Technique
- Genetic Algorithm Techniques
- Greedy Strategy as an Algorithm Technique
- Divide and Conquer Algorithm Technique
- The Backtracking Algorithm Technique
- More Pattern Matching Algorithms: B-M
- Pattern Matching Algorithms Demystified: KMP
- Coding Standards
- A Peek into the Future: Transactional Memory
- Learning About the Graph Construct using Gam...
- Learning About the Graph Construct using Gam...
- Learning About the Graph Construct using Gam...
- How to Strike a Match

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials