8

I've been asked to re-write (from the ground up) an existing C# winforms application. Unfortunately, this code has been modified by at least a dozen different developers over the past three or four years none of whom seemingly adhered to any kind of coding standard. To say that this code base is a mess would be putting it politely. Given the magnitude of the code (~24k lines) and the fact that the code is completely new to me, I'd like to find some kind of utility that will help me to more quickly understand how this application works at a high level. Bear in mind that there don't seem to be an abundance of good OOP practices in this code so I need something a little more detailed than class diagrams. I've seen references to generating sequence diagrams which might be more like what I'm looking for but I only have VS2010 Premium and I'm under the impression that this functionality is only provided with the VS Ultimate SKU. I have access to the current version of .NET Reflector and I've seen a couple of people mention that there are plug-ins for that which might be useful but I don't have any specific names.

tshepang
  • 12,111
  • 21
  • 91
  • 136
bmt22033
  • 6,880
  • 14
  • 69
  • 98
  • In order to find out what code is involved in a given task, I'd use a code coverage tool like PartCover or a (better) commercial alternative. That often helps me understand. However, I'm not posting as an answer because I don't actually remember how to do this. – Qwertie Apr 13 '11 at 17:02

3 Answers3

6

Rewriting the code from scratch can be a disaster: See this: http://www.joelonsoftware.com/articles/fog0000000069.html

This is not an easy task as you mentioned there were a dozen developers before you. Behind each developer is his own methodology and his own logic of the system. Everyone does it their own way.

Here are some of the problems you could encounter

  • Following another developers logic
  • Whether or not the developer is still around or has changed positions or worse changed jobs
  • Finding the or even if a technical specification exists (this is the most important)
  • Legacy code that was originally written, then patched, then patched again and again...
  • Custom code that might have been integrated or written within the application
  • Security if there is any

Besides having a bunch of flowcharts / diagrams of the application the best thing to ask for or obtain is the technical spec. What is the purpose of the program and given that 12 other people worked on it is it something you can take on yourself?

You mentioned OOP, do you plan to take spaghetti code and do an entire rewrite to fit the object oriented model? If so that is a lot of work...and with 12 prior brains working on it someone's logic is bound to trip you up.

Sorry I don't have the best advice, but this could be a daunting task...especially if those developers before you are no longer there.

See these SO threads for more info:

Community
  • 1
  • 1
JonH
  • 32,732
  • 12
  • 87
  • 145
  • Hi Jon. Thanks for your quick reply. You make many good points. Unfortunately, this is one of those situations where I'm being told that "this is what we're going to do". I actually did bring up some of these very same arguments to my employer but they've decided that a re-write is necessary and are committed to doing it (or rather tasking me do it, as the case may be). :-( – bmt22033 Apr 13 '11 at 14:12
  • If you have to rewrite (personally I enjoy those :D) you can try isolating pieces of functionality -- copy useful pieces into new projects and write unit tests -- to use in the new version. Oh and btw, when writing a new GUI app I'd recommend learning Update Controls - http://loyc-etc.blogspot.com/2011/04/update-controls.html - once you figure it out, it will accelerate development. – Qwertie Apr 13 '11 at 17:06
3

Have a look at NDepend, it is a code management tool that could help you a lot thanks to code querying, code rules, smart technical debt estimation, dependency graph and matrix, code diff since a baseline...

Oh, and this related question too.

Patrick from NDepend team
  • 13,237
  • 6
  • 61
  • 92
Larry
  • 17,605
  • 9
  • 77
  • 106
  • this one is free: https://marketplace.visualstudio.com/items?itemName=FerencVizkeleti.QuickDiagramToolforC – BlackFox Apr 20 '20 at 07:59
0

I'm pretty sure that, while the whole is invalid, some part of the existing code are perfectly good. I'd suggest that you take those part, put unit tests around them and gasp, copy paste them into your new project. That way, you will filter little by little your mess into something reshaped and tested.

Also, something I've always wanted to do is to print a lot of code and visualize the workflow by cutting (with real metal scisors) and taping them back together how they are used.

Eric
  • 19,525
  • 19
  • 84
  • 147