0

I'm working on medium sized ASP.NET MVC 4 web app, that is about 2.5 years old. Around 25-30k lines of code. The project has never followed any of the good .NET design practices. It is a very tightly coupled solution. There are not interfaces at all.

Do you think it is worth to upgrade the legacy/spaghetti code to follow SOLID principles and implement some design patterns? I know there is quite a good book to work with legacy code (don't remember the actual name).

The problem is that the project is constantly growing and the cost of refactoring is also growing every time new functionality is added. I wanted to spend some time to upgrade it, but when I looked into details of doing so, it overwhelmed me. There is so many changes needed that I don't know where to start with.

Has anyone got any experience with upgrading the legacy code? Was it worth it to spend so much time on it? Any ideas where to start?

gnat
  • 21,442
  • 29
  • 112
  • 288
  • 1
    Not every problem requires a rewrite. Look into the [BSP](http://programmer.97things.oreilly.com/wiki/index.php/The_Boy_Scout_Rule) – Robbie Dee Sep 27 '16 at 11:30
  • In my opinion it's totally worth it if you will still work on this code in the future (i.e. update, look for bugs, etc.). But you will probably have to explain to a non-developer that a code that works fine needs some work on it. They may not want to pay for an already working code. – Tim Sep 27 '16 at 11:31
  • see also [Where to start?](http://meta.programmers.stackexchange.com/a/6367/31260) – gnat Sep 27 '16 at 11:36
  • 1
    [Recommended reading](http://www.joelonsoftware.com/articles/fog0000000069.html). A rewrite isn't a silver bullet. – Robbie Dee Sep 27 '16 at 11:39
  • you were given [rather poor advice at Stack Overflow](http://stackoverflow.com/questions/39721550/how-to-go-about-upgrading-spaghetti-code-is-it-worth-it#comment66740560_39721550 "'You should ask this question in programmers.stackexchange.com'") - sorry about that – gnat Sep 27 '16 at 11:43
  • This is two questions in one. The first probably is a dupe, but the second maybe not. Maybe edit this question to focus on when code should be improved or just abandoned? – Tim Grant Sep 27 '16 at 12:02
  • @timster that was also asked and answered many times already, see [When is a BIG Rewrite the answer?](http://programmers.stackexchange.com/questions/6268/when-is-a-big-rewrite-the-answer) and questions linked to it – gnat Sep 27 '16 at 12:49
  • @gnat, that's good stuff, but I'd argue that "When should we decide to abandon a code base and rewrite?" is different than "When should we stop improving legacy code?" (For one, that big rewrite project management is talking about may never happen.) – Tim Grant Sep 27 '16 at 14:42
  • @timster check the linked questions I mentioned, eg [When do you rebuild an application or keep on fixing the existing one](http://programmers.stackexchange.com/questions/109262/when-do-you-rebuild-an-application-or-keep-on-fixing-the-existing-one) (that one is just first that popped - these matters were covered very thoroughly already) – gnat Sep 27 '16 at 14:48
  • 1
    If you think "SOLID principles" will produce a better design, you probably don't understand the existing design very well. SOLID is a set of guidelines useful in specific situations. – Frank Hileman Sep 27 '16 at 18:39

1 Answers1

0

Everything depends on how long is this project meant to last. In addition, you need to ask yourself one important question - if you are working in a team, is your team capable of writing a better quality code than the current one?

When it comes to time:

Just a few more weeks

Any kind of rewrite don't really makes much sense at this scale - when a new feature is needed or there is a bug to fix, simply expand existing code.

Few months

At this scale, you could consider rewrite of parts of code that are actively developed and using good practices in the code written in a future, but the whole code rewrite will most likely take too much time to be worth it.

Year or more

If the project is meant to last for a very long time, I think that total rewrite could be a good idea. Rewriting the program to use good practices should take much less time than it took to write it initially (but this will still take a considerable amount of time).

Mac70
  • 356
  • 1
  • 2
  • 11