Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simplifying code via refactoring

Is there a refactoring tool, either for C or Java that can simplify this type of redundant code. I believe this is called data propagation.

This is essentially what an optimizing compiler would do.

public int foo() {
    int a = 3;
    int b = 4;
    int c = a + b;
    int d = c;
    System.out.println(c);
    return c;
}

into

public int foo() {
    int c = 7;
    System.out.println(c);
    return c;
}
like image 257
Saideira Avatar asked Aug 26 '11 20:08

Saideira


1 Answers

I think it's not a good idea.

It's for example the following code:

long hours = 5;
long timeInMillis = hours * 60 * 1000;

That's much more cleaner and understandable than just:

long timeInMillis = 300000;
like image 166
Alfredo Osorio Avatar answered Sep 24 '22 08:09

Alfredo Osorio