1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <stdio.h>
#include <stdlib.h>

int foo(int c) {
    return c * 2;
}
int main(int argc, char* argv[]) {
    // BAD:  Data is repeated -- harder to check and tester... and fix.
    //       Makes code less versatile.
    int a = 1234598639;
    int b = 1234598639 * 23958;
    int c = 9999999989 * 23958;

    // BAD:  Same computation is *expressed* multiple times.
    if(a < 5) {
        b *= 234;  // Pull this out of the if statement and put it above/below
        c = 0;
    }
    else {
        b *= 234;
        c  = 1;
    }

    for(int i = 0; i < 20; i++) {
        int d = foo(c);  // NOT a DRY RULE issue ... just inefficient
    }
    
    return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */

© Copyright 2017 Alexander J. Quinn         This content is protected and may not be shared, uploaded, or distributed.