Using Call Hierachy for Refactoring of methods

Hey,

I just want to post a tip for the refactoring of methods, especially, if you want to delete them completely. With Visual Studio (and I think in almost all other IDEs), you can show the “Call Hierachy” of a method, i.e. you can see which methods are calling your method and which methods your method is calling.

Sounds complicated, but it can really help. For example, in the course we want to delete the AimAt Method in the tank. So what I did was to go to the .cpp file, make a rightclick on “AimAt” method and choose “View Call Hierachy”.

Afterwards a little window pops up with the option to expand “Calls to ‘AimAt’”. By expanding this, you will see (hopefully) all methods, which are calling “AimAt”. By doing so, you will have a better idea where you have to change code in order to remove all dependencies before deleting the method. You can also click the entries and Visual Studio jumps to the points where “AimAt” is called.

I (in particular) like this workflow and I hope it may helps you. Ben does not seem to use, but I think it really helps to refactor in a more methodical way :smiley: You can also check right before the deleting of a method, that it will not be called at another point in your code. Yes, the compiler will also tell you this, but a) C/C++ compilers allow for more than you would expect and b) error messages are hard to understand if you are new to stuff like this.

And sorry for my English, it’s not my first language :smiley:

Best,
Christopher

Privacy & Terms