Softpedia
 

NEWS CATEGORIES:



NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
Home > News > Webmaster > Tips and Tricks

September 28th, 2007, 14:48 GMT · By Catalin Bocanu

The Benefits of Code Comments

SHARE:

Adjust text size:


Example of a Well Commented PHP Code
Enlarge picture
In every programming language the programs or script codes should be easy to understand and clearly formulated. Besides this aspect of coding practice, the code should have explanations, notes, documentation and more. All of these are found in code comments.

Regarding the particular case of web programming
languages, the comments are lines of codes that will not be seen by the browsers. In the first place the code comments have the role to explain and describe the actions of a certain block of code, for example if you plan to share the script or application, or you will edit it after a long period of time.

In another situation, you can use comments to mask a line of code for a later utilisation or to compare two different instances of a given program action. In PHP and Javascript for example, you can use single line or multiple lines comments:

CODE
//this is a single line comment
/* this is a two lines comment
............................*/

The double slash comment can be used on multiple lines. For long codes there are special techniques for comment usage. You are not advised to use extensive comments in your own codes, but their necessity is obvious, because they will make the code more understandable for its readers or users.

Especially in educational situations, such as coding tutorials the comments should be used with care and well placed inside the code. You can avoid comments for certain variables if you will use suggestive names for their actions, destination, outputed values or purpose. The most commented should be the classes or functions where you are using many variables and all class documentation should result from your comments, because you can generate the class help by using parsers which extract the comments content, even on a hierarchical level.

In case you are a beginner or you just simply want to customize a code, the comments found inside of it should guide you to change the desired aspects of program actions. The comments could be used also for indexing purposes. In conclusion, the code comments provide users and developers many benefits, contributing in a significative percent to the achievement of optimal code portability between various platforms,readability and accessibility.

TELL US WHAT YOU THINK:

1,557 hits · Link to this article · Print article · Send to friend · Subscribe to news

MUST-READ RELATED ARTICLES:


The Basic Structure of a HTML Template

Web Site Development with WYSIWYG HTML Editors

A Simple Javascript Example

A Simple Calculator with HTML Forms and PHP

The World of PHP

READER COMMENTS:



No user comments yet.
Be the first to express your opinion!
Copyright © 2001-2012 Softpedia. Contact/Tip us at

WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM