Live data from Hacker News

Ask HN: How to tell someone you need to rewrite an entire project?

news.ycombinator.com

21–25 of 25 posts

Re: Ask HN: How to tell someone you need to rewrite an entire project?

#21
post #13

Send them this article: http://www.joelonsoftware.com/articles/fog0000000069.html Then, send it to yourself.

There are legitimate reasons for a full rewrite. If, for instance, you can change the platform and do the rewrite significantly faster than the original technology and implement changes faster, then the rewrite may be the may to go. Imagine you have an app built on J2EE, with lots of logic on templates and no tests whatsoever. It's huge and maintaining it takes a huge effort. Every bug takes weeks to fix and generate…

Your two "imagine" clauses are incompatible, though.

"Imagine you can write an equivalent app in Ruby on Rails in two weeks, with tests."

You've already said that the existing app has "lots of logic" and is huge. Every bug takes weeks to fix, which means the "lots of logic" is seriously twisted up and not easy to decipher.

If that's the case -- figuring out the logic to fix one bug takes weeks, then it's inconceivable that you'll untangle all of the logic in two weeks. That's before you write a single line of Ruby -- if you want an "equivalent" app, that means you have to know what the current one does, first.

This is the usually-fatal flaw in the "rewrite" argument. The existing app needs to be rewritten because no one can understand it anymore (is is both poorly-written and very large/complex). But because no one can understand it anymore, it will be extremely difficult to rewrite, unless you work as if you were creating a new, similar application.

This is also why refactoring works. You cut off a bit of the existing app, figure out just that bit, write tests for it, and then replace just that bit with new code.

You can even refactor an app into a completely different language, actually -- you have two apps running parallel, and gradually move over bits of functionality from one to the other. In the process you'll need to gradually enforce order (and separation of concerns...) on the original app, but you need to do that either way.

Re: Ask HN: How to tell someone you need to rewrite an entire project?

#22

Earlier quoted context omitted.

Code that is working and in use is worth roughly 10x your imaginary code that doesnt exist. So unless you could prove to me that the savings or value is 10X the cost to rewrite I wouldnt do it. Can you be more specific about why the code is bad? There are a limited set of architectural reasons for which I would support a complete rewrite. They typically correspond to non-functional requirements: 1) scale - the system…

One of the major problems within this project are poorly written, slow db queries, MVC is not correctly implemented (although using an MVC-based Framework, function names not intuitive. I can improve, refractor some aspects of the code, but the time that will took to fix it can be more than the time to recreate it in another framework. What do you think?

Poorly-written queries are very easy to refactor -- fix one query at a time, correct indexing strategy gradually, etc.

Likewise, function names are ideal to refactor -- many IDEs will automate this for you.

I don't know your situation, but this sounds to me more like framework envy (and I base this on experience... I've worked with projects on a lot of crappy and/or homegrown frameworks before). If you haven't actually done any major projects in the newer framework yet, that's a bad sign as well, I'm afraid. :)

On a more positive note -- it might be possible to incrementally move to a new framework. It's harder if you want to switch languages/environments completely, but if not, it's probably quite feasible (switch over a feature at a time). If both frameworks can access the same session storage... that's likely the main tricky aspect.

Re: Ask HN: How to tell someone you need to rewrite an entire project?

#23
post #21
post #13

Earlier quoted context omitted.

There are legitimate reasons for a full rewrite. If, for instance, you can change the platform and do the rewrite significantly faster than the original technology and implement changes faster, then the rewrite may be the may to go. Imagine you have an app built on J2EE, with lots of logic on templates and no tests whatsoever. It's huge and maintaining it takes a huge effort. Every bug takes weeks to fix and generate…

Your two "imagine" clauses are incompatible, though. "Imagine you can write an equivalent app in Ruby on Rails in two weeks, with tests." You've already said that the existing app has "lots of logic" and is huge. Every bug takes weeks to fix, which means the "lots of logic" is seriously twisted up and not easy to decipher. If that's the case -- figuring out the logic to fix one bug takes weeks, then it's inconceivabl…

No, they aren't incompatible.

First, a huge Java app is about 3 to 10 times smaller (in LoC) when ported to Ruby or Python.

Second, there is a lot of boilerplate code and configuration in a typical Java app. Not nearly that much with either Rails or Django.

And third, basic CRUD functionality, something that has tons of Java boilerplate associated with it, is usually very simple with Rails (or Django).

As for the tangled logic, it's the way many apps evolve. They are designed at their start and then refactored and patched into their current form. The current app wasn't designed anymore - it evolved - and, in order to properly maintain it, you'll have to understand how and why its evolution took place.

One more point - in order to reimplement it on top of a more modern framework, you don't need to understand thoroughly what your mutated-beyond-recognition Java app does - you only need to know what it should do. The fatal flaw you point out may not exist.

If you don't know what the app should be doing, then I have to agree - you are doomed from the start.

Refactoring will give you some time, as it reverses the mutations back into a designed state - and improve things a bit, but it will not be able to bring the orders-of-magnitude improvements you see when migrating from an old and obsolete (but still widely used) infrastructure, to a more modern one. That's when a rewrite would be warranted.

Re: Ask HN: How to tell someone you need to rewrite an entire project?

#24

Earlier quoted context omitted.

One of the major problems within this project are poorly written, slow db queries, MVC is not correctly implemented (although using an MVC-based Framework, function names not intuitive. I can improve, refractor some aspects of the code, but the time that will took to fix it can be more than the time to recreate it in another framework. What do you think?

for me the question is still, what problems is this causing? slow db queries can easily be isolated and unless they have done something like every write to the database creates an object which then gets converted to a sql transaction, function names can be fixed with global search and replace. Not sure what you mean by MVC is not correctly implemented

I mean that, model bits are inside controllers, for example :-)

Re: Ask HN: How to tell someone you need to rewrite an entire project?

#25
post #23
post #21

Earlier quoted context omitted.

Your two "imagine" clauses are incompatible, though. "Imagine you can write an equivalent app in Ruby on Rails in two weeks, with tests." You've already said that the existing app has "lots of logic" and is huge. Every bug takes weeks to fix, which means the "lots of logic" is seriously twisted up and not easy to decipher. If that's the case -- figuring out the logic to fix one bug takes weeks, then it's inconceivabl…

No, they aren't incompatible. First, a huge Java app is about 3 to 10 times smaller (in LoC) when ported to Ruby or Python. Second, there is a lot of boilerplate code and configuration in a typical Java app. Not nearly that much with either Rails or Django. And third, basic CRUD functionality, something that has tons of Java boilerplate associated with it, is usually very simple with Rails (or Django). As for the tan…

It sounds like you're referring to two different large Java projects, though. If you can port it by just stripping out the boilerplate -- if it's at heart just a CRUD UI with 7 frameworks and "enterprise best practices" mixed in -- then this is not the twisted and unmaintainable monster you're talking about afterwards. It's less fun, but I've worked on lots of sprawling & unwieldy Java apps implementing simple requirements, and it's not hard (it's also not easy to justify a rewrite, unfortunately). Bugfixes don't take weeks (or even days), particularly not once you know your way around a bit.

The app with the twisted logic (where bugs take weeks to fix, that has mutated over years and years of hacked-in change requests and quirky tweaks often for specific users' needs) is the one that screams for rewriting, but this is also the app where no-one knows exactly what it does anymore.

And if you don't know what it does, I have no idea how you could claim to know what it should do.

Many of the odd features are there for customers who aren't even customers anymore, but no one knows. Even the code doesn't always help much -- I've seen processing where it fails in the mid-method every time for some foolish reason (and logs an error then returns), but the code after the failure is actually direly broken and must never be executed.

I've tried (failed, actually) rewriting one of these as well as doing lots of refactoring on these kinds of projects.

With the first kind of app, you still understand it, so bugs can be fixed, new features are possible, and there's no clear case to rewrite it. With the second kind of app, you can either do what I mentioned above (and maybe you're talking about this, more than a rewrite?) -- start talking with/watching users, take a lot of notes, and build a new similar application all the way through, which will necessarily start off missing much of the functionality of the existing one.

Refactoring isn't about giving you time; it's about paying off technical debt and forcing the codebase back into a state where you can do progressively larger refactorings. This includes modularizing the existing app so that you can replace it piecemeal. New pieces do not need to operate within the old framework. It's quite possible (and sometimes desirable) to refactor the original codebase completely out of existence.

Post reply on HN