Development Cycles
  Home arrow Development Cycles arrow Page 4 - Coding Standards
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
VeriSign Whitepapers 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DEVELOPMENT CYCLES

Coding Standards
By: Gabor Bernat
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-03-05

    Table of Contents:
  • Coding Standards
  • The Advantages and Disadvantages
  • A Taste of Standards
  • More About Standards
  • Conclusions

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
    Iron Speed
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    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)

    {

    nxy="alfa"+a;

    Bool i;

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

    printf("%s",res);

    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

     

    printf("%s",result);


    if( result && i )

    {

    //the commands are

     

    return false;

    }


    return true;

    }

    More Development Cycles Articles
    More By Gabor Bernat


       · You may already figure it out that you can find your T-Shirt much easily if it has...
     

    DEVELOPMENT CYCLES ARTICLES

    - 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
    - Entity Relationship Modeling
    - Tame the Beast by Matching Similar Strings
    - 5 Web Design Tips You Can't Live Without
    - Practising Best Practises in Your Software D...
    - The Art of Modelling: Part 1
    - Thoughts on the Craft of Programming: Abstra...
    - Hi 5: Part 4
    - Domain Modeling: Leveraging the Heart of RUP...
    - Quality Vs Speed: Paradox Lost?


    Iron Speed





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway