views:

42

answers:

4

I'm in this situation with a project:

I need to implement a certain piece of functionality, which the code does I am working on not fulfill reliably. That is fine, but the implementation throws up exceptions about files in use (there is an instance class which reads and writes to a config file, and part of the problem is so many methods locally using the object, so there's all sorts of problems with state).

If you are in the process of implementing some functionality, but the primary means to do so is not reliable, due to the way the app is coded by others, what would be the best thing to do? I personally raise the issue with my manager and discuss an alternative. What would you do? Any stories from experience?

+1  A: 

A rewrite can take you a lot of time and pain. It is generally the last option I would consider unless you are dealing with a really small application. I don't have such an interesting story to tell but every time I face a dilemma like yours I remember the post by Joel Spolsky in which he describes how a complete rewrite of Netscape 4.0 led to ... Netscape 6.0, version 5.0 never got released!

I would try to detect the biggest problems caused by the multi-accessed object and see how much time it would cost to come up with a first batch of simple fixes and solutions. Having this information ready, you could discuss it again with your manager and maybe find a solution between a complete rewrite and ignoring the implementation's problems.

jdecuyper
Although I haven't come up with various fixes, I have the idea of a singleton, and that works. The app is small, but time is tight (as it always is), and this is the case of everything in this small app having to change, rather than a small part of a big app having to change (so it's a lot of changes).
dotnetdev
The idea of singleton is good. You will also have to make the access to the config file thread-safe. Is the application already in use? Because if it is, maybe you could push your new functionality and then in a next release (that you would have to negotiate), push the required changes to fix the singleton object.
jdecuyper
The app will be used by one user at a time, so there's no risk of data races, so that won't be an issue.
dotnetdev
+1  A: 

If adding a feature isn't easy, keep refactoring until it is easy. You'd be surprised how a solution emerges once you do some refactoring to make the scenario clearer.

Paul Betts
+2  A: 

On the technical front, there's no silver bullet answer. It takes a lot of refactoring. For environments like this, Michael Feathers book Working Effectively with Legacy Code has some great patterns. In particularly ugly code, you usually end up extracting the problem methods to classes and getting good test coverage around them. This allows you to bite off change in small pieces.

On the team front, you can't blame other people. You have to be the change agent and show how adopting refactoring and TDD make a difference.

Rob
+1 for no recrimination
whatnick
A: 

There's no secret. You just have to work through the problem. Present a solution, negotiate with the stakeholding parties, and refactor code. Repeat the process until you reach a resolution.

mikemerce