Home arrow Development Cycles arrow Page 3 - 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 - A Taste of Standards
(Page 3 of 5 )

The time has come to actually demonstrate some of the standards so you can better understand their usefulness and the advantages of a standardized code snippet. Here we go...

There are two types of naming standards accepted - Pascal casing and Camel casing. Each of them is recommended for a few situations, but before we venture into that, take a look at the differences between them.

Pascal casing -- First character of all words are upper case, while other characters are lower case.

Camel casing -- Each word has its first character upper case, except the first one, while the rest of the characters are all lower case.

YourName // Pascal casing

yourName // Camel casing

Use Pascal casing for class names, method names, and file names. Camel casing will be used for variable names, method parameters, and with an I prefix in the case of the interfaces. This way when you see a name without its declaration, you should already know what you are dealing with. As a side note, we can add that the Hungarian notation shouldn't be used anymore for variable names. Microsoft gave up on this at the introduction of .NET; instead, the Camel is preferred.

Always -- and I mean always -- figure out and use a meaningful name. When someone looks at it, s/he should already know its purpose. Do not use single character names; however, this rule can be violated in the case of the index loop variables. In any other situation a meaningful and self-explanatory name is the nicest way. For example, defining a variable that will hold a book's title as BookTitle is more advisable than naming it m23. The first path will result in code that is instantly perceived, even after ten years. Also for identifying a member variable quickly, use the ' _ '  underscore character in front of it, so logically it won't appear at any local variables.  

The use of prefixes is also a good thing. Insert the Is prefix in front of a Boolean type to indicate its type, and if you're using a user interface, then use the appropriate prefix for it. Look at some examples for these situations:

string _BookTitle; // and not ->> string m23;

int index; // for a local variable

for(int j=0;j<index;j++); //here the single character usage is permitted

Boolean IsTakenOut;

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-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials