I know I promised to do nothing but “includes,” and we’ll come back to those soon, but here is a real PHP routine, doing an actual real world job. What does it do? For a multi-author weblog like BloodhoundBlog, it produces a blogroll of the contributors’ weblogs or web sites. I’m sending this out to Morgan Brown, because Blown Mortgage is a multi-author blog — and because Morgan has joined ranks with Cheryl Johnson as a geek-blogger.
Why do this with software when it can be done with the “Links” feature within WordPress? Because a list done this way is self-maintaining. This code is based on the “Frequent Contributors” code on BloodhoundBlog — which would be a lot harder to explain. I added this last week when I upgraded to WordPress 2.3.2.
Here’s the code. I’ll go back through it and comment line-by-line:
<h2>Our Contributors' Web Sites</h2><UL>
<?PHP
$contribs = array(1,3,6,8,9);
$count = sizeof($contribs);
shuffle($contribs);
for($i=0;$i<$count;$i++)
{
$thisUser = $contribs[$i];
$curauth = get_userdata($thisUser);
?>
<li><a href="<?PHP echo $curauth->user_url; ?>"
target="_blank">
<?php echo $curauth->yim; ?></a></li>
<?PHP
}
?></UL>
Here’s the thing: PHP is a very sloppy language.
From Ada Lovelace to Kernighan and Richie, programming was always done with very tight, very clean code. Hardware was slow and expensive, so programmers were, relatively speaking, plentiful and cheap. Moore’s Law inverts that paradigm, with the result that any cost in hardware is worth bearing to maximize programmer time. This is why you’re always buying bigger, faster hardware, because programmers are sucking up every bit of it and then some. ANSI C was perhaps the apogee of the orbit for clean code: Strongly typed, strict syntax, unforgiving compilers. But, written right, C could get right down to the bone, running as fast, or almost as fast, as functionally-equivalent machine code.
PHP is like C in many, many respects — except that, like Javascript before it, it dispenses with type-checking, function prototyping, most syntax-checking, etc. It’s interpreted at run-time, not compiled, so there’s no compiler to catch errors. Instead of maximizing machine resources, PHP maximizes programmer time. It exists to let a skilled programmer bang out tons of original code in no time flat. Many other web programming environments are similarly loose, and, while this grates Read more