Tim’s comment challenge…

Tim Bray is considering the technology choices to add a comment system to his blog;

I’d like to take this occasion to learn at least one new technology.

Now he mentions Rails but reading his thoughts on the design would have to agree with his conclusion that that’s overkill. For a start why inject a long list of dependencies and a steep learning curve for a relatively simple application (that applies to any framework BTW – not just Rails)? Also as he’s leaning towards files not DB so no need for ActiveRecord etc.

Anyway – strikes me the most sensible solution would be just a CGI script (probably Perl) – he plans static output – the comments are “compiled” on approval – doesn’t need to handle high load but (to reduce the pain of that admin interface) needs to be easy to hack the UI once he can see where the time goes.

But wandering back to this discussion

I should really buckle down and try writing a PHP app

So taking a PHP tack – some random thoughts / discussion points;

  • Do we recommend Tim use a forms library? E.g. QuickForm or Patforms (related point – where do we point him for help installing PEAR if needed)? Against this is I doubt the comment form really requires a full forms library – vanilla PHP?
  • For comment markup, what to we want to point Tim at? As mentioned before, SafeHTML (packaged under PEAR as HTML_Safe) would allow posting raw HTML, perhaps with help from tidy to make sure it’s XHTML. There is PHP Markdown (don’t know much about this e.g. security record / UTF-8 handling) for a fairly standard markup. Alternatively Dokuwiki’s parser could be extracted (with a little hacking) – shouldn’t harm UTF-8 and shouldn’t result is broken XHTML. What else?
  • For authentication OpenID seems to be on it’s way to becoming a serious contender – it seems like Wikipedia is planning to support it some time this summer (more on that later) – there’s libraries in pretty much any common language, although can’t say how rubust the PHP stuff is.
  • A design somewhere in the realm of Rasmus’s no-MVC MVC, much as it’s controversial (see comments) design-wise, probably makes practical sense here.
  • For the XML generation he mentions, DOM or SimpleXML (which implies PHP 5.x+)?
  • What else to convince (or perhaps inadvertently discourage) Tim of PHP?

Free book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

  • Ryan Bates

    I agree that Rails may be a little over-kill for something so simple (especially if he’s not using a database), but how about just a Ruby script? Althought it may not be the best tool for the job, if he is intersted in learning Rails in the future, I think learning Ruby first and getting comfortable with that is the way to go. It really is an amazing and elegant language all on its own. It’s what got me first looking into Rails, and I’m very glad I did.

  • Andi

    Well I wrote a very simple one-file-one-table-only PHP solution. Just a few lines of code to integrate. Even comes with a capture mechanism and Gravatar support. Nothing fancy, no special text formatting (except URLs) but does it’s job. Have a look at the My Two Cents (MTC) comment system.

  • Fenrir2

    A simple Ruby script as CGI would be good, or maybe the Camping Microframework? (but even that would be an overkill).

    I would use a Ruby script if I could install it on a host. Use YAML instead of XML, it’s much easier than XML (even more easier than PHP’s XML, even SIMPLExml):

    comments = YAML.load('the-file')

    To load the file into a Ruby array/hash, and:

    comments.to_yaml

    To convert it back to YAML. I wouldn’t use Javascript to convert this to HTML, but I would let Ruby do that. Javascript could load the comments with Ajax, or in a frame (or maybe inline in the page).

    But if you want to use PHP:

    - No forms library, overkill, too much to learn for a beginner
    - Markdown, or if that gives your users too much power, PHP’s equivalent of Rails’ simple_format()
    - OpenID seems ok
    - No MVC MVC is excellent for this (small) script. Or just a file with MVC separated by database function library, controller code on top of php-file, template after the controller code.
    - SimpleXML is simpler, and he doesn’t need advanced things (and you could use xpath for that), so I’d use that. Or just vanilla-inline-PHP for XML generation.
    - Of course, there are languages like Ruby/Python/Javascript/Perl/Lua that are (IMHO) much more sane than PHP, but because most webhosts have PHP pre-installed, it might be better for a small script.

  • Anonymous

    related point—where do we point him for help installing PEAR if needed

    http://pear.php.net/manual/en/installation.php

  • Ivo Jansch

    If learning a new technology is the key point here, use rails, regardless of the overhead. That’s irrelevant.

    If you don’t care about learning a new tech, but do care about overhead, just don’t reinvent the comment wheel and download something that works out of the box.

  • Tijs

    He could integrate akismet’s anti spam system (http://akismet.com/development/), on my wordpress blog this filters out 99% of the spam

  • OfficeOfTheLaw

    Rasmus’s no MVC MVC is fun for the fact that all of his examples point to a “Sorry, we could not find the function blah blah” on php.net.

  • David Merrill

    Tim may be thinking what I’ve been thinking. I’ve designed a moderated comments system (Perl with a dash of Ajax) for newspaper web sites. Just hoisted it up the flagpole as a proof of concept, to gauge whether anyone’s interested enough to make it worth writing the admin interface. No database software involved, just Perl and a buncha text files on the server. Elemental, like my brain.
    http://www.orenews.com/internal/comments/CommentsOnYourSite.html