[advanced search]
Results from the most recent live auction are here.
19 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Go Back   NamePros.Com > Design and Development > Webmaster Tutorials
User Name
Password

Old 05-16-2008, 05:25 PM   · #1
DomainManDave
NamePros Regular
 
Trader Rating: (7)
Join Date: Jun 2007
Posts: 608
NP$: 13.30 (Donate)
DomainManDave is just really niceDomainManDave is just really niceDomainManDave is just really niceDomainManDave is just really niceDomainManDave is just really nice
Cancer
Smile Let me teach you about coding professionally!

Hello,

This is the first of many short articles/tutorials from me. Today we will be looking at professional coding standards. Read on, and enjoy.

The term "professional coding standards" relates to writing language instructions using clear, readable blocks of text, which include professional use of naming conventions, comments and multimedia compatibility. Let's break down each of these to learn more.

Naming Conventions

These are rules that help to determine the pattern for naming identifiers (variables, attributes etc) in the source code. Good use of naming conventions reduces the amount of effort required in understanding code and helps to make it more readable, compared to having excessively long names or very short abbreviations.

Let's have a look at two examples. The first example shows BAD use for naming variables and such. The second shows PROFESSIONAL use. PHP has been used for the following examples.

PHP Code:
$s = "Hello world";


PHP Code:
$message = "Hello world";


The second example gives us better understanding of the variables' use. We know it is a message of some sort to be outputted. In the first example $s could stand for anything and gives no indication.

There are many different types of Naming Conventions that are used in programming. The most popular and recommended notation is the Hungarian Notation, which identifies the purpose or type in the variable name by capitalizing keywords.

An example of using the Hungarian Notation would be as follows.

PHP Code:
$emailSubject = "Free holidays";


In the above example, "email" and "subject" have been separated by capitalizing the S. This shows that subject is related to an email. This gives us very good indication of what the variable is all about.

The same use applies to naming functions/methods. It is better to have a function called output than one called o, right?

Professional use of Naming Conventions helps to reap the following benefits.
  • Provides additional information about a variable/function
  • Maintains consistency in a team of engineers
  • Improves the appearance of the source code, making it look more professional
  • Better quality variable dictionary's for project documentation
  • Easier to remember, makes searching massive scripts in text editors a breeze
  • Productivity. Makes debugging and testing software a lot easier.

But isn't there still something missing..? Of course there is, comments!

Comments

Comments are used to describe certain portions of code, sometimes along with their pre-post conditions and post conditions. There are three key areas in any software file where comments are an essential asset.
  1. At the top of the file, where we describe the general purpose of the software along with vital pieces of information such as the package name, author, version number, revision date and license
  2. To describe the purpose of a specific function/method
  3. To describe important script variables

The comments at the top are very important. They let others who view the code know what its all about, its name, who wrote it, what version of the code they are viewing and so on. This is very important information because it provides everything other developers NEED TO KNOW about your software. If you don't provide comments then how can you expect to have professional collaboration between team members?

Let's take a look at an example of PROFESSIONAL commenting for the top of a file.

PHP Code:
<?php
/**
* This script contains useful methods for retrieving the contents of
* a website, including the title, anchor links and images. It uses cURL to
* retrieve the data and regular expressions to help match title, image
* and anchor tags.
*
* @package Website Content
* @author Fred Bloggs <fred@bloggs.com>
* @version 0.0.1
* @revision 12-May-08 16:40 GMT
*/
?>


I am sure most of those are pretty self explanatory. Package relates to the name of the package (software) this file/script is associated with. Author is the engineer who wrote it. But what about those other two? Let's go into a bit more detail.

Version - Many of you are most likely thinking, "Huh? why are you going into detail about version numbers!!?". Well let's be honest, how many of you actually know a logical way of determining the version for your software? And how many of you know the reasons for using version numbers? Well let me tell you.

A version number is actually read as [major].[minor][.maintenance] . The version number relates to the development progress your current major release of your software is. In the above example it shows as release 0, with no major or minor functionality and its first revision. Lets break down the three sections.

[major] - If this is a 0 then it usually refers to the software being in Alpha or BETA stage. Anything greater (1, 2, 3) relates to the latest major release of the software. This value will increment by 1 when there are significant improvements to the software. Significant improvements relate to the implementation of new features of the software or a complete revamp in design.

[minor] - This relates to minor or small improvements in the software, such as adding an additional few instructions for small things.

[maintenance] - This is incremented when bugs or errors in software are fixed.

In the comments, revision relates to the last time the file was revised (updated).

Version numbers and revision dates help aid with debugging bug reports and such.

The other important areas for commenting are for functions and variables. Function comments should clearly state the purpose of the function, what the various parameters are and what the return type should be.

Multimedia Compatibility

This relates to being able to view source code in different text editors and environments without causing the code to be spewed out all over the place. Let's never forget not everybody uses the same resolution or text editor, so we have to do our best to adapt to as many as possible.

The most important factors to consider are line lengths and white spaces. You should always indent blocks of code using SPACES (not tabs!!) to help them stand out clearly when being viewed across different editors and environments. Again, it makes for far more readable code because we know exactly where everything is without worrying about getting lost in a muddle of messy code.

Minimal line lengths help when viewing code on different resolutions. Sure, you maybe able to see a million characters on your uber awesome 5000 x 5000 resolution but what about that other poor developer who only has an 800 x 600 screen and word wrap on in his text editor? Uh oh!! The recommended
maximum line length is around 80 characters.

Let's look at a final example that puts together everything we have learned in this article and use indentation.

PHP Code:
<?php
/**
* This script contains useful methods for retrieving the contents of
* a website, including the title, anchor links and images. It uses cURL to
* retrieve the data and regular expressions to help match title, image
* and anchor tags.
*
* @package Website Content
* @author Fred Bloggs <fred@bloggs.com>
* @version 0.0.1
* @revision 12-May-08 16:40 GMT
*/

class WebsiteContent
{
    
/**
     * The title of the website.
     * @var string
     */
    
private $title = "";

    
/**
     * getTitle. Returns the title of a web page.
     *
     * @param void
     * @return string
     */
    
public function getTitle()
    {
        
// ....assume we get it here...
        // and then an example of inner block
        
if($title)
        {
            return
$title;
        }
    }
}
?>


Good use of commenting and naming conventions really help spice up your code and make it more clearer and readable. It also helps maintain professional work ethics and standards in an organizational structure and improves productivity.

Thanks for reading and I hope you enjoyed. This article really only covers the bare essentials about professional standards. To read more about topics covered here check out the links below.

Learn more about NAMING CONVENTIONS

Learn more about SOFTWARE VERSIONS



Please register or log-in into NamePros to hide ads
DomainManDave is offline   Reply With Quote
Old 05-16-2008, 07:53 PM   · #2
-Nick-
I'll do it
 
-Nick-'s Avatar
 
Name: Keral. Patel.
Location: India
Trader Rating: (97)
Join Date: Dec 2005
Posts: 5,233
NP$: 9541.05 (Donate)
-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute
Member of the Month
September 2007 Adoption
Very good one

I still remember about Microsoft standards that I read a while back when appearing for MCSD exams.

Some examples:

String variable = $strName
Integer = $intNumber
Boolean = $boolCorrect

Also helps other people in your project to understand what the variable is and how will it react if used in his part of code.
-Nick- is offline   Reply With Quote
Old 06-04-2008, 07:20 PM   · #3
ChosenDigit
First Time Poster!
 
Trader Rating: (0)
Join Date: Jun 2008
Posts: 1
NP$: 0.00 (Donate)
ChosenDigit is an unknown quantity at this point
Hi DomainMan, I will definitely join your class. I am actually looking for the section to introduce myself, but I popped into your class first. When is the next session?
ChosenDigit is offline   Reply With Quote
Old 06-04-2008, 10:22 PM   · #4
wikes82
NamePros Regular
 
wikes82's Avatar
 
Location: K-R.NET
Trader Rating: (36)
Join Date: Sep 2006
Posts: 801
NP$: 1701.73 (Donate)
wikes82 is a splendid one to beholdwikes82 is a splendid one to beholdwikes82 is a splendid one to beholdwikes82 is a splendid one to beholdwikes82 is a splendid one to beholdwikes82 is a splendid one to beholdwikes82 is a splendid one to beholdwikes82 is a splendid one to behold
Save a Life Cancer
Great tutorial.. though, I love to obfuscate my codes
__________________
#include <signature.h>
Accepting offer : FUYP.COM - HOYV.COM - OWKZ.COM
wikes82 is offline   Reply With Quote
Old 06-08-2008, 03:18 AM   · #5
mainstream
NamePros Regular
 
mainstream's Avatar
 
Name: Sha'rius
Location: Toronto, Canada
Trader Rating: (33)
Join Date: Feb 2008
Posts: 610
NP$: 0.00 (Donate)
mainstream is a name known to allmainstream is a name known to allmainstream is a name known to allmainstream is a name known to allmainstream is a name known to allmainstream is a name known to all
I wish I was smarter - God; why must you curse me with beauty as my only trait!!!


*joins class too*
mainstream is offline   Reply With Quote
Reply

NamePros is a revenue sharing forum.

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


Site Sponsors
http://www.mobisitetrader.com/ Proof is in the Parking Hunting Moon
Advertise your business at NamePros
All times are GMT -7. The time now is 02:19 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0