When I code in Mathematica, I often re-use code from old notebooks which fulfilled a specific purpose; for example, one testing for soft matches in strings, or one that identifies outliers on a graph and their index in the list. My code is generally written in a modular fashion using functions, such that I am able to immediately apply the function in my old code to the new data that I have.
The trouble with re-using code is that the function names I use in the old code and in the current code that I am processing sometimes overlaps. This most commonly happens with short function names such as
f within the main function, or function names such as
g which could double as a physical constant
g=9.81 ms-2. To avoid this, I try my best to code properly and give my functions names that are unlikely to be re-used.
However, I'm wondering whether there's a way to list all the functions/variables used in two separate notebooks and perhaps check the list of functions/variables for those used in both notebooks. These overlaps could then be resolved automatically (perhaps by appending a
notebook2 at the end of those functions/variables), or, more elegantly in my opinion, by allowing the user to choose the option of replacing all the duplicates in one notebook by another name.
In this similar question, separating variables between multiple notebooks is discussed, but this wouldn't really work in my situation since I actually want both codes to run in the same environment. I'm sure that the answers to this question would really help those who are engaged in large coding projects and attempting to re-use old code.