Blog for December 2006
19/12/2006: On The Legibility of PHP
David Segall wrote:
I do not deny that the programmer is the most significant factor in the readability of a program but would you really promote PHP as a language because it is easy to read?
I certainly wouldn’t advise against it because of legibility concerns.
Any language that supports comments (not all do) and allows the programmer to choose variable and function identifiers using arbitrary alphanumeric names (again, not all do) can be made very readable simply by using these facilities. With most common programming languages, you can easily clarify your code by having a policy that includes choosing sensible, readable function and variable names, using indentation and plenty of white space, adding liberal comments, keeping line lengths down to a reasonable length, keeping function sizes down to 20 or so lines (longer functions can often be split into two or more functions). Yes, even Perl!
For example, consider the following two (untested) PHP objects which are exactly…