Coding horrors from the past!

It’s nice to be back into coding for a while. Of course, one of the drawbacks is coming across code written over half a decade ago that should never have seen the light of day. Take for example this gem I ran across while continuing with my updating Keystone project…

$pq = db_query("select dtable,dcolumn,dflags from dictionary $wclause");
while ($pd = db_fetch_array($pq)) {
$varname = "op_$pd[dcolumn]";
eval("$oval="$$varname";");
$varname = "sp_$pd[dcolumn]";
eval("$sval="$$varname";");
if (empty($oval)) {
$oval=0;
}
$active = $sval ? "1" : "0";
$subtable = ($pd[dtable] == $proptable) ? '' : $pd[dtable] ;

It’s been said there’s a special hell for people who write code that uses the eval statement in production code. Apparently I’m headed there already. This was a very bad coding decision, but I remember actually writing this particular snippet. It was around 1998, and I was flying to California to talk with the company that would eventually buy Keystone from me. I seem to do some of my best coding work while flying on airplanes, though this sample isn’t exactly a sterling example of it. It did, however, enable one of the cooler features of the product – the ability to, using any of the various data sets, set up a custom browse view based on the structure of the table.

Using ‘eval()’ statements and depending on global variables was NOT the way to implement it though. Now that I’m converting all 12,000 some odd lines of Keystone code over to support running on a system that doesn’t have register_globals enabled, it was time to update this particular code snippet. It took a good 1/2 hour to figure out exactly what it was doing, but once I did that, it was a simple change to:

$pq = db_query("select dtable,dcolumn,dflags from dictionary $wclause");
while ($pd = db_fetch_array($pq)) {
$oval = $_POST["op_" . $pd[dcolumn]];
$sval = $_POST["sp_" . $pd[dcolumn]];
if (empty($oval)) {
$oval=0;
}
$active = $sval ? "1" : "0";
$subtable = ($pd[dtable] == $proptable) ? '' : $pd[dtable] ;
}

Don’t see much of a difference? It’s a big one from a code security and design standpoint. Don’t sweat it too much, it means a lot to me at least.

The conversion is moving along nicely though. I think I can have eval versions ready for folks to test out within a day or three, if I keep this pace up. I’ll be curious to see what sort of response I’ll get on the net to the system. It’s been a while.

Dusting off the Old

Back in the dark ages, I wrote a very successful ticketing system called Keystone. This was a successor to another reasonably successful program called PTS, which I wrote while working at Fidelity using this new fangled thing called ‘PHP/FI’. Online ticketing systems were still something of a novelty, and none existed in the opensource world (save for GNATS which, at the time, was an abysmal piece of code.
PTS, and later Keystone – flourished. In the dotcom runup, Keystone was a hot item. Whenever I posted a new version and announced it on Freshmeat, I would see thousands of downloads of the updated package within days. At conventions, I was well known. “YOU WROTE KEYSTONE? HOT DAMN!”
Alas, the dotcom era came along and an opportunity to sell Keystone dropped into my lap. I took it, along with a sizeable check, in exchange for an agreement with the new owners, that they would continue to support the product, as well as let me continue working on it.
Neither of these things actually happened. When the bubble burst, the owners found themselves holding a piece of software that they were not using, and still owed money on. The crunch came, I called in the debt, they couldn’t pay, so the entire system reverted back to me, lock stock and copyright, in exchange for me foregoing the outstanding balance.
On the one hand, yay, I got my program back. Hard to argue with that. On the other hand, 2 1/2 years had passed. The new owners had not touched the code, the industry had advanced a LOT in that time, and the competitors, which had excellent products at the time of the buyout, now had a 2 1/2 year jump on me.
Keystone languished.
Over the last few months, several people have been poking me about the code. Some clients have been running versions for YEARS, and are asking if there are updates coming. Others would like to set up new installations. I’ve half-heartedly worked on updating Keystone off and on a few times, but never really finished the changes into something I could release again.
Tonight I spent 2-3 hours dusting off the old code and continuing the updating process. Files with revisions half a decade old are coming up in my editor, with me vaguely remembering even writing them. But, the system works. It has some interface designs that I still find intriguing and useful, as well as it’s share of “WHAT WAS I THINKING?!?!?” elements. Like an old friend, though, the motions and patterns started up again – edit, save, flip, reload, flip, edit more… a dance step long disused, but not forgotten.
I fixed 4 bugs reported by the new users, committed and posted the changes, and updated the users’ vhost. Fixed. Problems brought up and addressed. Happy users.
I remember this.
It’s nice to be back with you, my old friend.