Quite a number of answers has been posted already, but I'll try nevertheless to add something useful.
First of all, refactoring of a big project is in most cases an economically unviable initiative. It will take significant amount of resources which will likely bring no ROI. It could last years! The internals may become better, the developers may get happier but that's all. It will not add more sales as the customers are not going to see any difference.
Just yesterday I read a Joel's article: Hard-assed Bug Fixin'. Not only has he a lot to say, but is a great writer as well.
As a software developer, fixing bugs is a good thing. Right? Isn't it always a good thing?
No!
Fixing bugs is only important when the value of having the bug fixed exceeds the cost of the fixing it.
The same even more applies to your situation. A bug can transfer its effect via customer dissatisfaction on to your sales and ultimately the company operation. How exactly do you expect an inconsistent coding style to have that same kind of effect?
Now the important part. You will have to refactor if the cost of maintaining and of further development of the application in its current state is higher then the cost of "fixing" it.
Different styles in code are almost inevitable in a big project with many people that contributed along the path. All of them have different experience, different conceptions of right and wrong, they set different priorities. You now see their "signatures" in code. The only way to avoid it is to write a consistent set of rules and strongly enforce them on every single developer from the very first day of the project. Choosing the right people for the job from the day one is also important. If you don't select people carefully but just pick up anyone who could do the work and not cost too much, you will get what you deserve.
The biggest issue here however is that you take the project personally. With all due respect to your attitude, it is not your project, it is not your business. I strongly believe that an employee should not care more than the management about how you do work (well, unless he is suddenly paid more than them). Many good developers have experienced the exact same frustration at work. There are three possible outcomes:
- you can't help it and leave
- you develop an apathy and a global loss of energy which may damage your health. There have been many people appearing in similar questions here who reported health problems developed at work that lasted for prolonged periods of time (months to years).
- you stop taking it personally and just do it for paycheck
I suppose I'm more or less in your situation. I also do not like the way the things are, the code itself is also badly structured, with my direct participation we brought one component to almost unmaintainable state - you change one little thingie and everything falls apart. The component itself is originally a quick solution to a sudden customer wish which since has enjoyed the style of development known as hacking things together. I also couldn't do anything about it. I was given the fuzzy instructions to come with the suggestions to improve it after I complained, but since I (and other people) have the other tasks coming in all the time including adding more to that component, I do not see any options to achieve that.
Now the hammer (as though it was not enough already). The more messy and unstructured the code is, the less are your chances of correctly extracting the complete set of rules and business logic from this part of the code. Which consequently means the chances of you refactoring this part without introducing any new bugs are equally low. There may have been several hundreds of bug fixings and customer wishes implemented, one layer over another, some of the documented, but most of them in the heads of customer employees (some of them may have already forgotten them or left the company) of your company developers (some of them already lost the track of changes or long since left the company). I see you're using C++, then this adds to the complexity of your task all memory allocation/freeing policies that may not be obvious to you now but will emerge at the first opportunity in your refactored code. So, technically evaluating your chances of doing it right, well, you see what they are.
My advice to you:
- What can be done? Not much, it is likely too late to change it on the big scale. Just do what you do the best way possible and maybe improve little things now and then where you can.
- Detach the personal bounding to the project and only consider it a job. Collect experience, write a blog about it.
- Whenever you can't stand it anymore, leave. The mental stability and the health state are more important than anything else.
Another great article about refactoring:
Things You Should Never Do, Part I
I'll cite for those who are not going to read it... :(
There's a subtle reason that
programmers always want to throw away
the code and start over. The reason is
that they think the old code is a
mess. And here is the interesting
observation: they are probably wrong.
The reason that they think the old
code is a mess is because of a
cardinal, fundamental law of
programming:
It’s harder to read code than to write
it.
and
The idea that new code is better than
old is patently absurd. Old code has
been used. It has been tested. Lots of
bugs have been found, and they've been
fixed. There's nothing wrong with it.
It doesn't acquire bugs just by
sitting around on your hard drive. Au
contraire, baby! Is software supposed
to be like an old Dodge Dart, that
rusts just sitting in the garage? Is
software like a teddy bear that's kind
of gross if it's not made out of all
new material?
Back to that two page function. Yes, I
know, it's just a simple function to
display a window, but it has grown
little hairs and stuff on it and
nobody knows why. Well, I'll tell you
why: those are bug fixes. One of them
fixes that bug that Nancy had when she
tried to install the thing on a
computer that didn't have Internet
Explorer. Another one fixes that bug
that occurs in low memory conditions.
Another one fixes that bug that
occurred when the file is on a floppy
disk and the user yanks out the disk
in the middle. That LoadLibrary call
is ugly but it makes the code work on
old versions of Windows 95.
Each of these bugs took weeks of
real-world usage before they were
found. The programmer might have spent
a couple of days reproducing the bug
in the lab and fixing it. If it's like
a lot of bugs, the fix might be one
line of code, or it might even be a
couple of characters, but a lot of
work and time went into those two
characters.
When you throw away code and start
from scratch, you are throwing away all that knowledge. All those collected bug fixes. Years of programming work.