The Importance of Organization within PHP
tion is the key to becoming a successful PHP programmer. Though it is easy to simply put together sloppy code for the sake of time, it is better to spend time organizing and structuring PHP code for easy manipulability and readability: it will save time in the end. Often, programmers revisit old code and find themselves in a mess of confusion and clutter. Avoid this by writing neat code the first time through. To write neat code, one must carefully comment, use functions and classes, and follow good programming style. Commenting code is an essential part of keeping neat, organized code. But the PHP programmer must understand when it is necessary to comment and when it is best to leave a comment out. If a block of code is very confusing or implements a tricky algorithm, it would generally be a good idea to leave a comment before that block of code explaining what it does and why. Comments should always include why the programmer did what he did—this is essential to anyone reading a PHP program's comments. Sometimes, it is better to rewrite code so that it is less complicated even if it means that there will be more lines of code. In addition, one should place a comment before any function or method explaining what input it accepts, what it does, and what output it gives; this makes perusing over functions and methods a breeze for other programmers. A well-versed PHP programmer should know not to over-comment code: many things are self-explanatory and do not require further explanation. In summary, commenting PHP code correctly can make reading old code easy and relatively painless. Secondly, it is essential for the good PHP programmer to use functions and classes in his code. The use of functions and classes largely increases the efficiency of PHP programs while maintaining a strong sense of structure. Use functions for any task that program uses more than once. Use classes to group functions and variables that work together to produce a single result. Be sure to name functions clearly and descriptively as well; however, do not go overboard in naming functions. Functions are also helpful in that they make the debugging process easier; a programmer can isolate a single function as the source of error, thus, eliminating hours of wasted time searching for a bug. Though functions and classes are not necessary in creating PHP programs, they are highly recommended because they organize code and save time in the end. Finally, following the rules of good programming style is essential for anyone that wants to become an expert PHP programmer. No matter what the circumstances are, always indent code to keep it organized—even if no one else will see the code. Indention vastly improves the speed at which someone can read code, which makes it easier to debug later. Be sure to name all variables, functions, methods, classes, and other programming structures appropriately. In addition, if possible, keep code consistent: if a PHP programmer uses one style of coding in the beginning, he should stick with it throughout the coding process. However, this may not always be practical. For example, often times many PHP programmers will work on one website together. Each may have a specific coding style slightly different from the other's. In such cases, consistency is not a necessity. Overall, good programming style identifies a good programmer and vastly improves the quality of PHP code.