Hacker Newsnew | comments | show | ask | jobs | submit login
Ask HN: Rewrite or Refactor?
3 points by oomkiller 2135 days ago | 9 comments
I'm working for a company that has an older Rails app, that is about 12,000 LOC heavy. It is currently running Rails 1.2.6. I am new to this project, but just looking at the code, it seems very PHP-like (at least one of the controllers is 1000+ lines) and is IMO garbage. It has VERY VERY slim unit tests (1:0.1 Code to Test Ratio), and those are mostly just the blank tests that the generator builds for you. They want my recommendation on what to do. I am leaning heavily to rewriting in the latest version of Rails, using the correct development and programming practices, as well as actually planning it out. They want to just keep maintaining the current app until they can rewrite it in .NET. They think that they can rebuild it in .NET in 6 months, which I believe is a gross underestimate. Should I suggest rewriting it from scratch in the new version of Rails, or should I try to refactor what they have into something better, possibly avoiding the need for .NET?

Thanks!




Nobody can tell you what's best for your application and team. But here's some comments:

Rewrites from scratch are pretty much always a stupid idea, and so you and the rest of your team are both probably wrong. Rewriting, in .NET or "new" RoR, is probably a waste of resources, and will probably introduce a whole new slew of stupidities and problems. Citation: http://www.joelonsoftware.com/articles/fog0000000069.html

12k LOC is less than 6 months worth of work for one motivated developer, for a reasonably specified application (a working example implementation is a reasonable specification). If you're a team working on it...well, if it takes you longer than 6 months, you've got bigger problems than just the ugliness of your codebase or the lack of test coverage. Then again, both you and your team are amateur enough to think rewriting is a great idea, and you're just arguing over which technology to rewrite it in, so maybe you can't actually finish it in 6 months. Maybe the practice and experience of doing dumb things and learning from those mistakes will help you all become better developers.

Anyway, even if it only takes 6 months, do you really want to be six months behind your competitors?

-----


Is it already in production? Making money/creating value? Refactor.

No, this is not a rule of thumb. But an app already in production has a lot of little quirks already ironed out. That report one person really needs every third Friday of the month. When an Korean speaking costumer on a Spanish Windows Vista 64bits running Flash 7.0 reported a bug on Internet Explorer 6 with Norton blocking the referer.

Code has knowlegde. Use it.

-----


If it is modular, reimplement one module in parallel and test. If there are no tests, add those first. If it is not modular, make it so, first.

If a single module can be ported to sane code successfully, you have a chance to fix the rest. If not, start reimplementing the whole thing in parallel. If you have no parallel test environment, create one first (so you can "deploy" your copy as if it were real).

It's all about the order in which you tinker with it. :)

-----


The solution to having no tests is adding tests. The solution to overgrown, unreadable, unmaintainable code is refactoring.

A rewrite would take about 2 years probably (using some very naive calculations).

-----


Dive in and start the re-write immediately.

This will inform either decision, and you'll look like you show a lot of initiative because you do.

-----


In my experience the best way to end these types of design arguments is just to start coding. If you're good you'll have a decent prototype to show off before the rest of the team has reached a decision.

-----


A lot depends on whether the code is unusable as-is - but it's a well established rule of thumb that a re-write of any codebase takes 3 times the back of the envelope calculation.

-----


refactor

It may be slim on unit tests, but it passes one huge integration test (people are using it!). You can add unit tests as you refactor, and make gradual progress.

Rewriting from scratch you will need to relearn all of the knowledge that already has been put into that code, and it's an all-or-nothing bet.

-----


If they want to rebuild it in .NET, it's a lost cause.

-----




Applications are open for YC Winter 2016

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: