Practices
  Home arrow Practices arrow Page 4 - Writing Quality Software: A Primer
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM Rational Software Development Conference
 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? 
PRACTICES

Writing Quality Software: A Primer
By: Steve Adcock
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 23
    2003-12-15

    Table of Contents:
  • Writing Quality Software: A Primer
  • Some General Quality Issues
  • Consistent and Readable Code Format
  • Naming Conventions
  • Appropriately Commenting Your Code
  • Unit Testing
  • System Testing

  • 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
     
     
     
    ADVERTISEMENT

    Dell PowerEdge Servers

    Writing Quality Software: A Primer - Naming Conventions
    (Page 4 of 7 )

    An issue that many developers neglect is naming conventions. Some hasty programmers use the first word that comes to mind when naming variables, which hurts the intuitiveness of the application. Variable names need to accurately reflect the variable's purpose in life.

    Let's take a look at some good and bad naming conventions, using PHP.

    $A = 15 // Bad name 
    $Age = 15 // Good name 
    $P = 4 // Bad name 
    $Perimeter = 4 // Good name 
    $Date = "01/14/04" // Potentially good name 
    $RetireDate = "01/14/04" // Better name 
    


    Always use the shortest variable name that you can, while still maintaining the meaning of what the variable holds. Let's again look at a few examples.

    $CircumferenceOfTheCircle = 4 // Name is too long 
    $CircumCircle = 4 // Better name 
    $MaximumPointsPossible = 100 // Name is too long 
    $MaxPoints = 100 // Better name
    


    Both $CircumCircle and $MaxPoints satisfy both of our examined criteria, (1) the variable name implies the value, and (2) the variable names are both concise. Try to avoid using words like 'the', and 'a' and other filler words within variable names, along with 'ing', 'ed', 'ies' etc. They violate both our criteria.

    Also notice my use of capitalizations. It is often easier to read variables when using initial caps for each word. So, instead of $Maxpoints, I wrote $MaxPoints. Some programmers only capitalize the first letters of words other than the first, for example, $maxPoints. Either method works fine, although I prefer to initial cap each word, including the first.

    Another method to naming your variables includes a reference to the datatype in the variable name. Although this does lengthen our variable, it does add understanding to what the variable should hold. Using this method, instead of declaring our "First name" variable $FirstName, we could declare it as $strFirstName. And, instead of declaring our Boolean variable "Success" $Success, use $bolSuccess.

    How do we tell the difference between local and global variables? Unless they are declared within functions themselves, it may not be initially obvious. Consider tacking on g_ for global variables and f_ for function variables (or m_ for module variables). So, our global variable called $Multiplier could be renamed to read $g_Multiplier. This way, when other programmers read your code, or even when you read your code months from writing it, it is clearly understandable that g_Multiplier is a variable used globally, and you will look for such usage.

    To wrap up, here's what you should have learned:
       

    PRACTICES ARTICLES

    - The System in So Many Words
    - Basic Data Types and Calculations
    - What`s the Address? Pointers
    - Design with ArgoUML
    - Pragmatic Guidelines: Diagrams That Work
    - Five-Step UML: OOAD for Short Attention Span...
    - Five-Step UML: OOAD for Short Attention Span...
    - Introducing UML: Object-Oriented Analysis an...
    - Class and Object Diagrams
    - Class Relationships
    - Classes
    - Basic Ideas
    - Choosing the Right Team
    - Trees
    - Basic Array Searching in C++

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




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