At work I inherited development of a PHP-based Web site after the consultant who originally produced it bailed out and left without a trace. Literally half of the code is ripped from online tutorials, and there are thousands of lines of cruft that, being incomplete, do precious little. Hardly any of it actually works. I've been trying to pull out the usable components, such as the layout (cleverly intermixed with code), session management (delicately seasoned with unescaped, unvalidated SQL queries), and a few other things, but it's very difficult to force all of this junk into place. Further, I don't speak idiomatic PHP, being more of a Perl user, and I'm supposed to be on this project principally for maintenance, so rewriting everything seems like it would take just as long as wrestling the existing monster back into place.
As an aside, I have literally never seen anything as badly written as this. Welcome me to the world of working with other people's code, I guess, but I do hope it's not this common in the real world to have such gems as these:
// WHY IS THIS NOT WORKING
// I know this is bad but were going for working stuff right now...
// This is a PHP code outputing Javascript code outputting HTML...do not go further
// Not userful
I'm looking for the best advice I can get here. What would you do if you were in my position?
Edit: Thank you, everyone, for your speedy and helpful advice!
Explain the problems to your manager, indicating that the support costs are going to continue to mount unless you remove the technical debt in the code. Recommend that he go for a rewrite as soon as possible, using the existing system as a template for the features, i.e., 1-1 replacement as the goal. Since a significant fraction of the development time is figuring out what you need to do, this shouldn't take as long as the original. Having a competent developer on it might mean that it will only take a fraction of the time.
Let your manager do his job -- compute ROI on the replacement project -- and make the decision.
Really it depends on the size and scope of what you're looking at.
As it relates to your scenario in particular, if the work is simple yet the code is broken, you'll probably save a heck of a lot of time just rewriting it. You won't be inheriting any legacy cruft or poor design choices. With respect to web sites, there are tons of frameworks and/or open source solutions you can just map the existing site to without significant effort.
Looking at your code example above, looks like it might also be worthwhile submitting your code snippet to thedailywtf.com. ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With