Originally legacy code meant code 'inherited' from authors or from a previous program/system version. Since Michael Feathers published his "Working Effectively with Legacy Code" book, new definition came to be, where code without tests is legacy code.
Questions tagged [legacy-code]
480 questions
231
votes
34 answers
What to do about a 11000 lines C++ source file?
So we have this huge (is 11000 lines huge?) mainmodule.cpp source file in our project and every time I have to touch it I cringe.
As this file is so central and large, it keeps accumulating more and more code and I can't think of a good way to make…

Martin Ba
- 37,187
- 33
- 183
- 337
128
votes
3 answers
Coding Katas for practicing the refactoring of legacy code
I've gotten quite interested in coding katas in recent months. I believe they are a great way to hone my programming skills and improve the quality of the code I write on the job.
There are numerous places where Katas can be found.…

mezoid
- 28,090
- 37
- 107
- 148
83
votes
3 answers
Why cast free's return value to void?
I am reading a book (Programming with POSIX Threads by Butenhof, 1997) that uses C, and I came across the following line:
(void)free(data);
Here, data is just a pointer to an allocated struct,
data = malloc(sizeof(my_struct_t));
Why is the result…

Adam Johnston
- 1,399
- 2
- 12
- 23
83
votes
8 answers
Adding unit tests to legacy code
Have you ever added unit tests, after the fact, to legacy code? How complicated was code and how difficult to stub and mock everything? Was the end result worthwhile?

BuckeyeSoftwareGuy
- 1,037
- 1
- 8
- 9
81
votes
19 answers
What's the best way to become familiar with a large codebase?
Joining an existing team with a large codebase already in place can be daunting. What's the best approach;
Broad; try to get a general overview of how everything links together, from the code
Narrow; focus on small sections of code at a time,…

RJFalconer
- 10,890
- 5
- 51
- 66
68
votes
8 answers
Dead code detection in legacy C/C++ project
How would you go about dead code detection in C/C++ code? I have a pretty large code base to work with and at least 10-15% is dead code. Is there any Unix based tool to identify this areas? Some pieces of code still use a lot of preprocessor, can…

Nazgob
- 8,502
- 4
- 40
- 42
39
votes
11 answers
What can you do to a legacy codebase that will have the greatest impact on improving the quality?
As you work in a legacy codebase what will have the greatest impact over time that will improve the quality of the codebase?
Remove unused code
Remove duplicated code
Add unit tests to improve test coverage where coverage is low
Create consistent…

Craig Angus
- 22,784
- 18
- 55
- 63
38
votes
4 answers
Advice on working with legacy code
I need some advice on how to work with legacy code.
A while ago, I was given the task to add a few reports to a reporting app. written in Struts 1, back in 2005. No big deal, but the code is quite messy. No usage of Action forms, and basically the…

Tom
- 43,810
- 29
- 138
- 169
37
votes
8 answers
Method for finding memory leak in large Java heap dumps
I have to find a memory leak in a Java application. I have some experience with this but would like advice on a methodology/strategy for this. Any reference and advice is welcome.
About our situation:
Heap dumps are larger than 1 GB
We have heap…

Rickard von Essen
- 4,110
- 2
- 23
- 27
36
votes
2 answers
Installation of VB6 on Windows 7 / 8 / 10
I have been having problems installing VB6 on Windows 7. I realize it is a legacy IDE and my research on the net hasn't been that much of help. Every time I attempt to install VB6 on Windows 7, besides the alert notifying me of compatibility issues,…

EthiopionZA
- 797
- 2
- 9
- 13
34
votes
7 answers
Dead code detection in PHP
I have a project with very messy code - lots of duplication and dead code here and there.
Some time ago there was zero code coverage by unit-tests but now we're trying to write all new code in T.D.D. manner and lowering technical debt by covering…

BinaryButterfly
- 18,137
- 13
- 50
- 91
33
votes
3 answers
How to change method behaviour through reflection?
I have a a static method in some legacy code, which is called by multiple clients. I obviously have no options to override it, or change behaviour through dependency injection. I am not allowed to modify the existing class.
What I want to do now is…

dev
- 11,071
- 22
- 74
- 122
32
votes
7 answers
Implicit int return value of C function
I've googled and just can't seem to find the answer to this simple question.
Working on a legacy code base (ported to Linux recently, and slowly updating to a new compiler) and I see a lot of
int myfunction(...)
{
// no return...
}
I know the…

LeviX
- 3,096
- 3
- 28
- 41
30
votes
4 answers
Redirect both cout and stdout to a string in C++ for Unit Testing
I'm working on getting some legacy code under unit tests and sometimes the only way to sense an existing program behavior is from the console output.
I see lots of examples online for how to redirect stdout to another file in C++, but is there a way…

thelsdj
- 9,034
- 10
- 45
- 58
27
votes
4 answers
How to find out if certain javascript code is actually used?
I am doing some JavaScript cleanup work on a legacy project, and trying to get rid of redundant JS libraries. I have done all the obvious ones (those that are not references from anywhere at all). But there are a number of JS files that are included…

Ashkan Aryan
- 3,504
- 4
- 30
- 44