I use Extract Method from C and face some problems:
1. The function is often placed below the function it was extracted from (seems to occur most often when there are no other functions above:
int f()
{
return MyMethod();
}
int MyMethod()
{
return 1*2;
}
which means it will not compile.
2. On bigger projects I have tried this on the behaviour is very strange (I have not been able to reproduce it in any test code):
// Extracting the if statement
int f2()
{
int a;
if (a != 0)
{
a = 1*2*3;
}
return a;
}
// becomes
int f2()
{
int MyMethod( int a )
{
if (a != 0)
{
a = 1*2*3;
} return a;
}
int a;
a = MyMethod(a);
return a;
}
Sometimes it even puts it inside another function earlier in the source file.
3. Function calls within the code extracted will sometimes be extracted as parameters (unable to verify this in test project):
// Extracting the if statement
int f1(int b)
{
return b*2;
}
int f2()
{
int a,b;
if (a != 0)
{
a = f1(b);
}
return a;
}
// becomes
int f1(int b)
{
return b*2;
}
int MyMethod(int a, int f1, int b )
{
if (a != 0)
{
a = f1(b);
} return a;
}
int f2()
{
int a, b;
if (a != 0)
{
a = f1(b);
}
return a;
}
/Johannes