Take the 2-minute tour ×

Well , I have been asked to work in a Java web application that is very very poorly designed . In the name of "making this easy" , they have come up with their own "framework" to make things extremely difficult to understand . I am struggling to figure out the control flow . Do you have any such experience ?

What do you do in such situations when the guy who has "designed" it has already left the company ?

share|improve this question
It sounds like this relates closely, but is probably not the same as: programmers.stackexchange.com/questions/29671/… –  Erik Romijn Mar 3 '11 at 6:56
haha, join the club mate, there are many of us in your situation ! –  DavidM Mar 3 '11 at 9:28
@DavidM The Club-Mate? –  Konrad Rudolph Mar 3 '11 at 11:02
@Konrad, that's probably what you need at the end of a day working on such projects :-) –  DavidM Mar 3 '11 at 11:15

9 Answers 9

up vote 5 down vote accepted

While trying to figure out how this works, it's probably a good idea to write unit-tests for it. That way you know what happens when a parameter enters and in the future you still know you haven't broken it. Perhaps even refactor it a bit so you can use Dependency Injection so the unit tests can remain small. This probably isn't easy, so first try to write some scenario-unit-tests and make them smaller while you progress. This way you can make sure the application remains stable and you learn a bit out of it.

If you got time, I'd suggest reading this book a bit Working Effectively with Legacy Code. It has really nice pointers on how to act in such a situation.

share|improve this answer
+1 on unit tests. –  Heiko Rupp Mar 3 '11 at 7:09
Good suggestions, however, in my experience, most poorly written code is virtually untestable. –  Vadim Mar 3 '11 at 14:17
You can start by calling a method with it's parameters and see what it does. After that, perhaps refactor it a bit, but most of the time that's, indeed, hardly possible. –  Jan_V Mar 3 '11 at 14:46

In my short 3 years career I had 3 products to maintain in such condition. And form me there is 3 periods in my mind:

  1. That guy was idiot. (for 2-3 months) Why do such awful things? It seems he wrote code did't thinking about next day, when he or anybody else have to extend it. Refactoring all code.
  2. Wow! There is some great code, maybe his was genius (for 1-2 months). Refactoring some code.
  3. After fist two periods - Now all code is almost refactored by me. I hope next guy how maintain my code don't think I'm big idiot :)

At first you should read line by line and try to figure out, how code works, personally I draw maps on paper. After couple weeks of this you can almost easy do changes and do not much harm for rest of a code. Latter refactor bit by bit, and you could change everything knowing you don't harm any yours and previews code.

share|improve this answer

I've the exact same feeling whenever I have to use Struts and most other "frameworks"...

Get used to it, most if not all software is poorly designed. The more design went into it, the more likely its design is to be poor (as exemplified by the worst designed application I ever worked with, which was massively overdesigned by someone who had written books about software design and applied every single one of them to that system at the same time).

share|improve this answer

Do you have any such experience ?

I have almost exclusively such experiences :-) Most of the projects I have worked on were legacy projects. It is difficult to understand someone else's code, especially if it has a long history of changes. It may originally have had a nice and clean architecture, but without constant care and refactoring, any design will inevitably rot over time.

I have answered a similar question on SO a while ago, before PSE came into existence. Hope it helps you too.

Although that question (and my answer) would now fit better here, I though it better to avoid duplication, so I just link to it rather than copying the text.

share|improve this answer

Do you have any such experience ?

Yes. I almost said "of course".


You deal with it. It is part of your job. How you deal with depends on what the application is, and how bad the problem is, but it ranges from:

  • Put up with it because it is not really that bad.
  • Progressively rewrite / refactor it.
  • Throw it away and start again.
  • Throw it away entirely ... or institute a permanent code freeze.
  • Put up with it because it is too hard or too expensive to fix.

Depending on the nature / extent of the problem, you may need to bring it to management's attention. But you may have to deal with the issue of convincing management that the problem is in the code ... not in your ability.

And remember that the corporate world is full of crufty old code-bases that are too hard / too expensive to fix or replace. The typical management viewpoint is typically that something that works (just) well enough doesn't need fixing.

share|improve this answer

It's a tough spot. You can try to find anyone in the organization that has any experience with the application at all. Short of that, you're just going to have to bite the bullet and start reading the code and stepping through the debugger as you trace your way through some use cases. Start with simple ones, then work your way from there.

share|improve this answer

A good and simple way to learn about the control flow is to hook up a profiler. Go into the app, start CPU profiling and then execute the action you want to know about. When this has finished, stop CPU profiling and have a look at the generated call graph. This will give you the complete path from front end (UI) pages and actions to biz logic in the server up to the sql statements going to the DB.

share|improve this answer

Unfortunately, you're going to suffer more with this current position than the code-hopefully not. Some had a great idea initially that they would build this great framework and the rest of the code would just fall into place. Then reality sets in. Right in the middle of the framework project someone wants to see more of a working site so they can demo to investors, sr. management, business partners, or some VIP. So they have to stop what they're doing and put something together. Just when they thought they were back on track, someone needs a change to the old application because of some regulation, law, or a typical business whim.

Eventually, someone expects this project to be on time or since the demo went so well, you should be ahead of schedule. Never mind that the accounting department had to delay their testing for two weeks (Didn't anyone mention end of quarter?).

Now you show up. They expect you to pick up where your predecessor left off. You're constantly fighting the desire to start all over again instead of learning the Framework to the Matrix. You'll find out it is not so complicated as long as your class names are palindromes.

Fix this mess. Be the unsung hero and wait for the next project so you can write your own framework.

share|improve this answer

I think almost every developers meet such situations.

The point is "poorly designed" can run, even it works fine online.

Conservative strategy is: refactoring it by small step by step, it's safe for you and your code:)

share|improve this answer

Your Answer


