Monday, December 29, 2008

Saving Time By Using Comments In PHP Programming

By Chris Channing

Because of how PHP is structured, which is to say it is done so that anyone can use it according to their own style, developers don't have to make use of PHP comments. But the truth is, most professional web developers, if not all, stress that making use of comments in PHP is vital in keeping organization and improving readability for future use.

The reason comments are so handy is because they are only viewed by those looking at the source code of the original file- not the viewer of the website. Best yet, they aren't even visible to those who try to view the source code of the website, since PHP code is hidden from the browser when being properly used.

It's often a better idea to use PHP comments in place of others such as HTML comments, since PHP comments will never be seen by the end user if the script is running correctly. This simple fact will help safeguard against others stealing source code, ideas, or principles from an application.

Comments are created with three different calls. For comments that span two or more lines, we have to use "/*" and "*/" - and "#" or "//" for single line comments. Comments in PHP can actually be placed directly after real PHP code, above it, or below it. This leaves a lot of creativity in how developers document their code according to their style and tastes.

Unbeknown to most, PHP comments can also be used for more practical scenarios, such as troubleshooting. Expert programmers will find they have a problem with their application, and comment out different blocks of code to see what is causing the error. While it is usually in new code blocks, this method will indeed show that sometimes the problem is due to program code interacting wrong, which can in effect mean the problem is anywhere in the application.

One big use of commenting in PHP is to use comments in selection structures, whereas comments are placed in every possible choice given. Often, developers close selection structures, such as the IF structure, without commenting what each choice does since we don't always use every choice. But by defining each choice early on, this saves quite a bit of time down the road once developers start nesting loops and selection structures inside each other.

In Conclusion

The Internet is full of many examples of how to creatively use PHP comments. Try scouting out some websites for more information on the usage, concept, and execution of comments to get better experience with this blessing. As developers find, an early history with commenting in programming is always the best route. - 14915

About the Author:

No comments: