Find any methods that are never called?
-
Is there a way to find any methods that I have defined that never actually get called in my code? Not that I have any like that
I've found a few little methods that I started writing while testing something, then later found a completely different solution, but then never realized I needed to get rid of that old method. So is there such a code cleaning tool? Well, I don't want it to touch my code, I'll do that, I just want it to point me to methods that are not being called ever.
-
I just use
Notepad++
and 'find
' each 'def
' in turn; I use 'find
' for the method's name 'xxxx
' and do acount
, if it ==1 I know I've never used it in the script; to be doubly sure I then add=begin...=end
around the method and retest the script [NB: restart to clear unused methods]: if it works with no errors then I know it's safe to remove that unused method. It it looks like a useful method snippet I'll cut/paste it into a methods-scraps file for possible use on another project, otherwise I'll just delete it! -
@tig said:
add =begin...=end around the method and retest the script:
Make sure to restart SU before retesting. Because a
load
will not remove the old method. Easy trap to fall into, as you won't notice something failed until you start the next time.
Advertisement