Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reuse, Rewrite, or Refactor?

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!

like image 879
Jon Purdy Avatar asked Apr 14 '10 19:04

Jon Purdy


2 Answers

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.

like image 149
tvanfosson Avatar answered Oct 05 '22 21:10

tvanfosson


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. ;)

like image 21
Braintapper Avatar answered Oct 05 '22 22:10

Braintapper