Ask HN: Rewrite outsourced code or refactor it?

1 points by ashray ↗ HN
Alright, so I'm in a unique mess. Joined a startup, found out that their entire codebase was built by an outsourcing shop (who didn't care much for code quality) and am wondering how to proceed. The startup is about 1 year old. Their codebase is in PHP. There's no in-house team at the moment but we're working on that.

The app isn't super complex (yet) because they were waiting to add most of the complexity once they could get a proper dev team. The code is a mess though, here are some things:

- Inline SQL statements

- Inline PHP inside of on-page javascript

- Pages aren't even W3C validated (or even close!)

- No tests at all

- No data modeling whatsoever

- Tons of PHP related inconsistencies in the data int 0 is false - obviously.

- And much more!

Our choices are:

- Continue in PHP and try to refactor

- Switch to python with Django or something and do a full rewrite.

Underlying db is MySQL. Currently, I'm the only developer but we're looking for more. However, if we do decide to rewrite I'd look for the python variety - otherwise I'd go down the PHP road. (I'm comfortable in both, worked with both in production)

HN Gurus, what are your opinions on refactoring vs. rewriting such a code base ? Everywhere I look people say "Do not rewrite, you'll kill yourself" but almost every time the condition of the code doesn't seem quite like this.. at-least not in the way it's described.

3 comments

[ 3.3 ms ] story [ 15.7 ms ] thread
If the app isn't super complex yet, just sever the relationship with the outsourcing shop and rewrite it.

The "Do not rewrite, you'll kill yourself" advice only applies when the code has history. Legacy code has actual users that expect it to work a certain way, and has been tweaked over the years to cover cases that you aren't thinking about when you first start a project.

Your code isn't that. Your code is a prototype that you should feel fine about throwing away.

Thanks for the advice. Yeah we're severing the outsourcing relationship from this week onwards. The plan is to hire an in house dev team and I just want to make the right decision about the way forward.

I wouldn't say that the code is a prototype but it sure is an MVP. There are tons of issues with it and one thing about refactoring that scares me is that we may not necessarily hit all the buggy corners of it and may end up with some corrupt data.

Rewrite it, I have been in situations like this before and I wonder why I did not rewrite it.