

Ask HN: Rewrite outsourced code or refactor it? - ashray

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.<p>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:<p>- Inline SQL statements<p>- Inline PHP inside of on-page javascript<p>- Pages aren't even W3C validated (or even close!)<p>- No tests at all<p>- No data modeling whatsoever<p>- Tons of PHP related inconsistencies in the data int 0 is false - obviously.<p>- And much more!<p>Our choices are:<p>- Continue in PHP and try to refactor<p>- Switch to python with Django or something and do a full rewrite.<p>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)<p>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.
======
bhousel
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.

~~~
ashray
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.

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

