Blog for 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…
25/03/2006: Sample PHP Source for Non-Interrupting Logins
Noozer wrote:
User opens a page. A session starts and they are asked to log in. They spend 30 minutes reading the page, then clicks a link. Since they were on the page for 20+ minutes their session ended. At that point they are asked to log in, and then taken to their chosen page as if never interrupted.
Reasonably easy, yes. This example is in PHP, but the same idea should work for other languages…