So now I have 12 functions all called foo defined in the same file, with the same number of arguments? I would find the person who wrote that and yell at them. Then I would just change the name, compile and fix the errors.
No, I don't think /u/Deathspiral222 was saying that. What he was saying is that over your entire codebase, you have 12 functions named the same thing. He uses foo() as an example, but it could be something common like a getter called getName(). He now wants to rename the base function to bar() in one case. A find/replace won't help you here, since it will find calls to every foo() function, instead of only the specific one you want to rename.
I'm not sure how you can do that when talking about Java. Sure, you have the base case of "import com.bar.Something" where Something contains your foo method and I guess you can look for that but then you also need to look for things like "import com.bar.*" and then you also need to look for explicit references like:
"Foo foo = com.bar.Something.foo()"
and all those are doable but then you have to deal with code that extends Something like:
"public class SomethingTwo extends Something {
public void foo()"
and then you'll have to find both all code that references the file or extends the file.
and so on and so on.
Eventually you realize that you can't get all instances of a specific foo() without a crazy amount of coding.
Ah, I misunderstood you. So say you have 2 methods with the same name, but different signatures (same number of args though). Can you grep your codebase for calls to the specific method included in that file with those specific arg types?
So now I have 12 functions all called foo defined in the same file, with the same number of arguments?
No. You have a large codebase and you have, say, twelve unrelated classes, all with a foo() method in them. I want to change only the references to foo() for THIS SPECIFIC CLASS, not the other eleven.
Those references could be in 100 different files, and there could be 1000 other references to OTHER methods called foo() in other files, but I just want to rename the 100 that refer to this specific class. This is really hard to do, especially when the class is extended etc.
You need something that "understands" the entire codebase to do this and it's something IDE's excel at.
Basically any refactoring operation like "move method" or "rename class" needs to understand the context in order to update all references to that item without updating other things that happen to have the same name. Once you get into a large codebase with hundreds of developers, it's just about certain that multiple classes will have methods with the same name.
1
u/thrashmetal Sep 25 '15
So now I have 12 functions all called foo defined in the same file, with the same number of arguments? I would find the person who wrote that and yell at them. Then I would just change the name, compile and fix the errors.