Going insane from work
I haven’t talked much about work on this blog and I’m not going to give too many details now, either. For a bit of background, I’m working on somebody’s many-years-old legacy code, much of it written in a mix of PHP and Perl. The code has been worked on by dozens of programmers over the years, and nobody’s really kept any documentation aside from that absolutely required (mostly inter-departmental stuff).
As a result, the code is… well, let’s just call it The Code From Hell™.
So TCFH is a mixture of really old and not-so-old, and over the years the (very many) changes have resulted in a huge amount of cruft. None of which can be removed because, there being no documentation (and very little structure to the code, thanks to a number of people’s preferred coding style of “let’s just make this fucking thing work so I can go home”), nobody knows what’s still in use and what isn’t. On top of all this, “code reuse” was, at some point, taken to mean “let’s make a copy of this thing and make a couple of small changes, making it work for this new situation”.
In conclusion, we’ve got:
- lots of versions of basically the same file with a few small changes
- many old pieces of code nobody’s ever looked at in years
- unused code
- code that’s in use, but is so convoluted (the term Spaghetti Code comes to mind) that everybody hopes it won’t break
- and very few, very confusing and mostly outdated pieces of documentation describing how some parts work (there is no complete documentation of the whole thing. If there ever was, it’s way out of date now)
And, to top it all off, I’m one of only two people remaining who still understand most of how it all fits together, and I’m the junior with only one and a half years’ experience.
On the bright side, most of the code is readable, once you understand a few basic structuring ideas that were, for the most part, adhered to.
It’s the rest of it (about 20%) that gives people nightmares of being stuck in a maze of twisty passages, all alike. I worked on that 20% today.
Let me pause now to describe a bit of the process flow: first, a user clicks a “join” link on one of our websites. The link takes them to the credit card processor, where they enter their CC details and their card is either accepted (and billed) or declined. After a successful billing, the user is sent to a handler on our servers that takes care of setting things up on our end; namely, creating the user in the database, and remembering some associated information so they can be rebilled for as long as they keep up their subscription.
Except that, on three websites, the user is not being created in the database.
The success/fail handler is one of those old pieces of code that’s been around since the dawn of time. There are multiple copies of it, as well as a number of included files which are about as old as the rest of the whole thing. I went through one of the copies today. Or I tried to.
You see, the code is part of that Code From Hell I was talking about. And even the includes are convoluted. So I thought I’d make things easier on myself by writing a script that recursively follows includes and prints them in a tree-like format (this script will be made available to others in the future; watch this space, or ask me for it, I might give it to you if you’re not a jerk).
The result? 177 included files, of which some 20 are false positives (not really includes; or commented out), about 30 are includes of the exact same file, which is used in a lot of places to provide unified logging, some 20 more includes of another file which provides some translation between an id number and the website the action originated on (lots of sites all go through the same handler; don’t ask for details unless you want to make me cry (meanie)), and some 20 or more includes of files defined by variables like $FNAME.
What none of these files seems to do is add a fucking user to the fucking database!
So I’ve basically wasted about five hours hunting for something in age-old code, still haven’t found it, my brain feels like it’s been through a grinder (multiple times), my wrist started hurting a while ago (carpal tunnel scare, though it’s since stopped), and the only success I’ve had so far today is this quick script that follows includes.
I’ve joked about taking this whole mess and rewriting it in PHP, but to be perfectly honest, I think one of these days I’m gonna go rogue and do it. Over a few weekends. And then present the result to the folks on the other end and say “Hey, guys, you know, it can be done better”. And it’ll be structured this time, dammit!

XHTML: You may use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
RSS feed for comments on this post. TrackBack URI