Questions tagged [dead-code]

Dead code is code in the source code of a program which is executed but whose result is never used or a code that can never be reached or used.

Dead code is code in the source code of a program which is executed but whose result is never used or a code that can never be reached or used.

Dead code is waste of computing power and might result of unexpected behavior to the program.

Examples:

int foo (int a, int b)
{
    int c = a + b;  // dead code - executes and result never used 
    return a - b;
}

void foo ()
{
     bool a = true;
     if (!a)
     {
         // dead code - never called
     }
}
238 questions
319
votes
19 answers

How can I know which parts in the code are never used?

I have legacy C++ code that I'm supposed to remove unused code from. The problem is that the code base is large. How can I find out which code is never called/never used?
user63898
  • 29,839
  • 85
  • 272
  • 514
318
votes
21 answers

How to find unused/dead code in java projects

What tools do you use to find unused/dead code in large java projects? Our product has been in development for some years, and it is getting very hard to manually detect code that is no longer in use. We do however try to delete as much unused code…
knatten
  • 5,191
  • 3
  • 22
  • 31
166
votes
7 answers

How find all unused classes in Intellij Idea?

There is an inspection "Unused declaration" which can find all unused code in Intellij Idea. (see How to use IntelliJ IDEA to find all unused code?) But I want to find all unused classes, not methods, variables etc. Only classes. (it is difficult to…
Cherry
  • 31,309
  • 66
  • 224
  • 364
102
votes
8 answers

How to find dead code in a large react project?

In order to refactor a client-side project, i'm looking for a safe way to find (and delete) unused code. What tools do you use to find unused/dead code in large react projects? Our product has been in development for some years, and it is getting…
Sinane
  • 1,614
  • 2
  • 12
  • 17
92
votes
8 answers

Can branches with undefined behavior be assumed unreachable and optimized as dead code?

Consider the following statement: *((char*)NULL) = 0; //undefined behavior It clearly invokes undefined behavior. Does the existence of such a statement in a given program mean that the whole program is undefined or that behavior only becomes…
usr
  • 168,620
  • 35
  • 240
  • 369
87
votes
6 answers

How can you find unused functions in Python code?

So you've got some legacy code lying around in a fairly hefty project. How can you find and delete dead functions? I've seen these two references: Find unused code and Tool to find unused functions in php project, but they seem specific to C# and…
Brian M. Hunt
  • 81,008
  • 74
  • 230
  • 343
76
votes
8 answers

find dead JavaScript code?

We are refactoring a legacy web app and as a result are "killing" quite a lot of JavaScript code but we're afraid of deleting what we think is dead code due to not being sure. Is there any tool / technique for positively identifying dead code in…
JoelFan
  • 37,465
  • 35
  • 132
  • 205
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
54
votes
7 answers

Dead code identification (C++)

I have a large legacy C++ project compiled under Visual Studio 2008. I know there is a reasonably amount of 'dead' code that is not accessed anywhere -- methods that are not called, whole classes that are not used. I'm looking for a tool that will…
Rob Walker
  • 46,588
  • 15
  • 99
  • 136
54
votes
8 answers

Unreachable code error vs. dead code warning in Java under Eclipse?

Does anyone know why: public void foo() { System.out.println("Hello"); return; System.out.println("World!"); } Would be reported as an "unreachable error" under Eclipse, but public void foo() { System.out.println("Hello"); …
Uri
  • 88,451
  • 51
  • 221
  • 321
40
votes
9 answers

Will my compiler ignore useless code?

I've been through a few questions over the network about this subject but I didn't find any answer for my question, or it's for another language or it doesn't answer totally (dead code is not useless code) so here's my question: Is (explicit or not)…
Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142
30
votes
3 answers

if(false) vs. while(false): unreachable code vs. dead code

I tried the following in Eclipse: if (false) {}: warning 'dead code' while (false) {}: compilation error 'unreachable code' I was wondering whether there is a real 'reason' for this difference. I already found this... Unreachable code compiler…
luukburger
  • 637
  • 6
  • 14
27
votes
4 answers

Does "dead" code hinder Java application performance?

I just installed the Unnecessary Code Detector for Eclipse and ran it on my project. I see a lot of so-called "dead code". Although, from an organizational standpoint, it makes sense to remove dead/unnecessary code, it got me thinking: Does dead…
user1768830
20
votes
2 answers

How to remove dead code from Javascript

I am trying to remove unused functions from my project. Since it has thousands of lines, this takes forever. Code coverage tools may suggest functions that are not used in a given test case, but it may be dangerous to rely only on this. Is there…
Yuvals
  • 3,094
  • 5
  • 32
  • 60
20
votes
1 answer

Detecting unused Spring beans

Given a Spring configuration that exclusively contains eager (non-lazy) singleton beans, i.e. the defaults, is it possible to have Spring throw an exception in the case where any of those beans is not injected anywhere? I'm essentially looking for a…
jaco0646
  • 15,303
  • 7
  • 59
  • 83
1
2 3
15 16