Comments are only intended for the programmer. They will not be displayed or executed. They identify as part of the program without interfering in the program. Comments are among the trivial elements in the success of a program; and this is why it is important to use them with intelligence.
We’ll be covering the following topics in this tutorial:
A comment, what is it?
A comment in a programming language, is a line written in natural language (mother tongue of the developer for example) will not be executed by the interpreter (or compiler according to the language used). Its function is to describe or explain some of the code that will reveal is difficult to decipher for maintenance or collaborative work (multiple developers working on the same program).
The comments are therefore particularly useful for a developer, but they are more so when it is a complete team working on the same project. They allow to impose among other nomenclatures and organization in writing the code of a collaborative project. In addition, the comments provide easier maintenance program by its author or a third party.
Another highlight of comments is the generation of technical documentation. Indeed, there are applications such as PHP Documentor that relies on a particular syntax comments to generate documentation for an application. This ensures a significant time saving for a development team.
Comment code is also part of good programming practices to adopt. But it still not be entered to the other extreme where each instruction code become commented. The clarity and readability of the program would then be affected.
The Linear Comment
There are two kinds of comments. The comment on a single line and multi-line comment. Let us look at both methods to review a text on one line.
Comments on a single line
<?php
// This is a first line comment
echo 'Hello World!';
echo'<br />';
# This is a second line comment
echo 'Hello World' ;
?>
PHP offers two ways to comment on a text placed on a line. The most widely used method is the first example with the double slash (//) unlike the second using a pound sign (#).
The multiline comment
It allows to comment a written text on multiple lines. It is very frequently used by developers. These comments are defined using symbols /* and */. The example below illustrates their jobs.
Multiline comments
<?php
/*
This program was written by Emacs
It displays the string 'Hello Word!' on the screen
*/
echo 'Hello World!';
?>