To install click the Add extension button. That's it.

The source code for the WIKI 2 extension is being checked by specialists of the Mozilla Foundation, Google, and Apple. You could also do it yourself at any point in time.

4,5
Kelly Slayton
Congratulations on this excellent venture… what a great idea!
Alexander Grigorievskiy
I use WIKI 2 every day and almost forgot how the original Wikipedia looks like.
Live Statistics
English Articles
Improved in 24 Hours
Added in 24 Hours
Languages
Recent
Show all languages
What we do. Every page goes through several hundred of perfecting techniques; in live mode. Quite the same Wikipedia. Just better.
.
Leo
Newton
Brights
Milds

Redundant code

From Wikipedia, the free encyclopedia

In computer programming, redundant code is source code or compiled code in a computer program that is unnecessary, such as:

  • recomputing a value that has previously been calculated[1] and is still available,
  • code that is never executed (known as unreachable code),
  • code which is executed but has no external effect (e.g., does not change the output produced by a program; known as dead code).

A NOP instruction might be considered to be redundant code that has been explicitly inserted to pad out the instruction stream or introduce a time delay, for example to create a timing loop by "wasting time". Identifiers that are declared, but never referenced, are termed redundant declarations.

YouTube Encyclopedic

  • 1/3
    Views:
    1 516
    598
    2 341
  • Removing Redundant Code - JavaScript Testing
  • Alternating Operations - Refactoring Redundant Code
  • Java Clean Code Tutorial #1 - Eclipse Compiler Build Errors & Warnings Preferences

Transcription

Examples

The following examples are in C.

int foo(int iX)
{
    int iY = iX*2;

    return iX*2;
}

The second iX*2 expression is redundant code and can be replaced by a reference to the variable iY. Alternatively, the definition int iY = iX*2 can instead be removed.

Consider:

#define min(A,B) ((A)<(B)?(A):(B))

int shorter_magnitude(int u1, int v1, int u2, int v2)
{
    /* Returns the shorter magnitude of (u1,v1) and (u2,v2) */
    return sqrt(min(u1*u1 + v1*v1, u2*u2 + v2*v2));
}

As a consequence of using the C preprocessor, the compiler will only see the expanded form:

int shorter_magnitude(int u1, int v1, int u2, int v2)
{
    int temp;
    if (u1*u1 + v1*v1 < u2*u2 + v2*v2)
        temp = u1*u1 + v1*v1; /* Redundant already calculated for comparison */
    else
        temp = u2*u2 + v2*v2; /* Redundant already calculated for comparison */
    return sqrt(temp);
}

Because the use of min/max macros is very common, modern compilers are programmed to recognize and eliminate redundancy caused by their use.

There is no redundancy, however, in the following code:

#define max(A,B) ((A)>(B)?(A):(B))

int random(int cutoff, int range)
{
    return max(cutoff, rand()%range);
}

If the initial call to rand(), modulo range, is greater than or equal to cutoff, rand() will be called a second time for a second computation of rand()%range, which may result in a value that is actually lower than the cutoff. The max macro thus may not produce the intended behavior for this function.

See also

References

This page was last edited on 6 March 2023, at 11:44
Basis of this page is in Wikipedia. Text is available under the CC BY-SA 3.0 Unported License. Non-text media are available under their specified licenses. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc. WIKI 2 is an independent company and has no affiliation with Wikimedia Foundation.