On Wed, Oct 30, 2002 at 10:26:41AM +0000, Andy Wardley wrote:
> PHP is, or should be, a quick hack language.  The fundamental feature 
> of embedding application code directly in presentation markup is the 
> biggest no-no there is.  It leads to a poor (or non-existant) separation
> of concerns, typified by spaghetti code programs that are all but impossible 
> to read, understand, extend and maintain.

Unreadable spaghetti is a function of the programmer, not (generally) of
the language.  Certainly, embedding code in presentation does *not*
automatically lead to spaghetti.  And I maintain that *any* templating
language is code embedded in presentation.

My own little noddy PHP-a-like for embedding perl code in HTML certainly
doesn't automatically lead to unmaintainable spaghetti, because it lets
you do anything in it that you could do in perl, including shifting your
code out into modules.

Here's how you'd display a perl hash as an HTML table ...

<table>
  <tr>
    <th>key</th>
    <th>value</th>
  </tr>
  <perl>
    foreach my $key (%hash) {
  </perl>
  <tr>
    <td><em><perl>print $key</perl>:</em></td>
    <td><perl>print $hash{$key}</perl></td>
  </tr>
  <perl>
    }
  </perl>
</table>

Yes, you're right, I never got round to interpolating variables directly
into the HTML, but that would be REALLY trivial to add in, and I'll do it
if the lack of it annoys me enough.  This is no different from the way
it would be done in any other templating system, the one difference being
that I was too lazy to invent my own little language and decided to use
perl instead.

If I need to get at more complex logic, I can move it out into a module,
C<use> it as necessary, and then do something nice and simple like the
above to display the results.

> PHP is quick, simple and easy to use and ideal for basic one or two
> page web hacks.  But for building larger sites or dynamic web applications?
> Definately not!

I'm sure I've heard the unenlightened say the same about perl too.

> Alas, that's what most large dynamic web applications seem to be written
> in these days.  Written by your average Joe who wouldn't know the 
> difference between good programming and bad, and probably wouldn't care
> much about it if they did  :-(

Ahhh, so you do see where the problem is.  The particular flavour of
templating matters not.  How it is abused does.

> ASP is just as bad for much the same reasons.  Used by people who don't
> know any better and don't want to know any better.

And perl is just as bad for the same reasons.

-- 
David Cantrell | Member of the Brute Squad | http://www.cantrell.org.uk/david

         Nuke a disabled unborn gay baby whale for JESUS!

Reply via email to