views:

84

answers:

5

My new project is to renew Software that a customer had used for years. Like we all know...things grew over the years.

So i looked at the old app. get all Infos about it and wrote a lot of user stories down. After cleaning it up i recognized that i made (in the end) a mistake that leads to the same problem that the customer has now.

It is a different Mistake i made but really annoying.

How do you guys prevent such mistakes. Do you refuse looking at the old app?

A: 

Unit testing. But if you didn't have unit tests from before, they wont help you.

Zak
Unit tests don't prevent mistakes planning the project.
Georg
Main Problem about that is that my program is actually working the right way. So it is no real programming mistake. Hard to find such design issues with Unit testing.
bastianneu
A: 

This question sounds like you are modifying existing code by "cleaning it up" as opposed to rewriting it. This process is sometimes referred to as "Refactoring". There is a great book on refactoring called "Refactoring" by Martin Fowler. He starts by giving concrete examples of refactoring on actual code, and links the future chapters about specific techniques he is using right there next to the code.

One of the very first things he says about refactoring is to write a test to test that the code you are changing does the same thing for some common set of inputs. Then when you "refactor" the code, run the test against it to ensure it is functioning exactly the same. This can be pre-bugfix or post-bugfix. But if there is a bug, of course you have to squash it in addition to refactoring.

Zak
Refactoring is a great Idea. Since it is a different type fo App (Access made) it might get difficult. I am building a new Grails Based Wep App.
bastianneu
A: 

Why rewrite from scratch? You may be able to reuse parts of the existing application and refactor those parts that need changing.

parkr
It is an old Access Based App. A little bit outdated and not strong enough to match customer needs anymore.
bastianneu
A: 

When I go about to recreate something that has already been done I try to avoid looking at the already existing implementation. I try to focus on what it’s supposed to accomplish instead of looking at how it’s trying to accomplish that.

Bombe
Yeah i agree with you. But what about special customer needs that are already built in? Do you ask the customer for that...i accomplish that by reading the code and testing the app.
bastianneu
That’s basically the same: you have to find out what the application is supposed to do not what it’s currently doing. When looking at the existing source code you’re bound to duplicate existing bugs—which is exactly what you’re trying to avoid. To prevent that you’d have to contact the customer and find out what it is that they really wanted to have.
Bombe
+2  A: 

This is a really hard problem. I'll describe what I would do (and have done) if the old code is substantially large.

In general, the old code is full of decisions, bug fixes and undocumented behaviors. If you throw that away, you're bound to make many of the same mistakes they did and then some more.

For what it's worth, you should evolve the system around the old code. Try to abstract away from the old code, e.g., by creating interfaces, and then implement them by calling the old code at first. Write lots of unit tests for the interfaces, and gain knowledge about how the old code works. New features should gain new implementations, so old code and new code will live side-by-side, for as long as needed, and maybe even forever.

Now, slowly and carefully make incursions into the old code, refactoring it, replacing it, and making sure that your tests still pass. Write new tests as well. If you have regression tests for the system (apart from the unit tests), they still need to pass.

It's OK not to touch the old code, typically if it's working OK, there're no bugs reported for it, it passes your tests, and it doesn't need to be extended.

Some good resources:

http://martinfowler.com/bliki/StranglerApplication.html

Working Effectively with Legacy Code

I've also found it in StackOverflow already:

http://stackoverflow.com/questions/330220/strategy-for-large-scale-refactoring

Jordão