Tag Archives: programming

Code Poet

The longer I work in software, the more convinced I am that the term “computer science” is mostly hogwash, as it applies to software development. Writing software is a lot more like writing a story than it is like baking a cake or doing qualitative analysis of soil samples. Given the same task, 3 programmers will do it 5 different ways, and each will have its unique beauty, its unique ugliness, and its unique ways to solve the tricky problems that come up along the way.

I’m lucky enough to work with some folks who have very creative ways to solve problems, rather than cut-and-pasting someone else’s solution.

And it never ceases to amaze me how every industry, no matter how stodgy or boring of itself, provides opportunities for unique creative expression. And no matter how much experience I have, I keep encountering folks with far less experience, but far more creativity and talent. I firmly believe in the old adage that one should hire people smarter than oneself.


Long, long ago, Steve Hancock gave us PerlTidy, which allowed me to quickly and reliably convert raw Perl code into code that abided by all of my coding standards, whatever they might be for a particular project. This was much goodness.

I even have a vim macro that allows me to select a block of text, type a key sequence, and have that code reformatted so that it is more easily readable, evenly indented, and just prettier.

For many years, I’ve looked for a similar tool for PHP. I’ve seen references to something that Coogle did, but I can’t actually find it, and it doesn’t completely sound like what I’m looking for anyways.

Apparently the problem is that the intermixing of form and function (html and php) that happens in php code, makes this a more difficult problem than just parsing and reassembling source code. I naively think that there must be a simple way to treat HTML as comments and ignore it, but seeing as I have not the vaguest idea of how to go about this, it’s kinda of condescending of me to make such claims. What do I know?

This morning I discovered that PerlTidy works, some of the time, to tidy up PHP code. And, of course, sometimes it doesn’t, because part of what PerlTidy does is inspect the Perl code itself, in order to determine how to format things, and PHP code doesn’t generally parse as valid Perl, except when it does.

When I was learning PHP, I observed repeatedly that it was almost exactly the same as Perl, in most respects, most of the time. This gained me many dirty looks from the “Perl is evil” PHP programmers I encountered, but, since language bigotry has never struck me as a survival strategy, I continue to maintain this belief. Indeed, this belief allowed me to uncover features of PHP that I don’t frequently see used, and aren’t very well documented, but I discovered blindly by assuming that PHP should behave the same as Perl if I need it to. And most of the time it does.

Ahem. Back to the point.

I find numerous postings on various blogs and mailing lists, where people are bemoaning the lack of a usable PHPTidy tool. I’m really curious why it’s a hard problem. I don’t understand what’s involved in doing this, in the least, either in PHP or Perl, so I have no real notion of whether it is hard or not. What gives?