Hubbry Logo
search button
Sign in
Redundant code
Redundant code
Comunity Hub
History
arrow-down
starMore
arrow-down
bob

Bob

Have a question related to this hub?

bob

Alice

Got something to say related to this hub?
Share it here.

#general is a chat channel to discuss anything related to the hub.
Hubbry Logo
search button
Sign in
Redundant code
Community hub for the Wikipedia article
logoWikipedian hub
Welcome to the community hub built on top of the Redundant code Wikipedia article. Here, you can discuss, collect, and organize anything related to Redundant code. The purpose of the hub is to connect peo...
Add your contribution
Redundant code

In computer programming, redundant code is source code or compiled code that is unnecessary. Code that can be removed without affecting its desired behavior is redundant.

Categories

[edit]

Noteble categoreis of redundant code include:

Recomputing
Recomputing a value that has previously been calculated[1] and is still available.
Dead code
Code that is executed but has no external effect; e.g., does not change the output produced by a program.
Unreachable code
Code that is never executed. Also, called dead code.
NOP padding
A NOP instruction might be considered redundant if it's for padding. But if the NOP is required for proper functionality then it's not redundant.
Unused identifier
Declared, but never referenced is a redundant declaration.

Examples

[edit]

In the following C code, the second x * 2 expression is redundant code. Line 2 can be removed, or alternatively, line 3 can be changed to return y;.

int foo(int x) {
    int y = x * 2;
    return x * 2;
}

A more subtle example involves the C preprocessor that inserts code before compilation. Consider:

#define min(A,B) ((A)<(B)?(A):(B))
int shorter_magnitude(int a, int b, int c, int d) {
    return sqrt(min(a*a + b*b, c*c + d*d));
}

After preprocessing, the code expands to code that evaluates both a*a + b*b and c*c + d*d twice. To eliminate the duplicate code, the macro min could ge converted to a function.

int shorter_magnitude(int a, int b, int c, int d) {
    return sqrt(((a*a + b*b)<(c*c + d*d)?(a*a + b*b):(c*c + d*d)));
}

See also

[edit]

References

[edit]