SyntaxBomb - Indie Coders

Languages & Coding => BlitzMax / BlitzMax NG => Topic started by: Ashmoor on July 14, 2018, 03:53:21

Title: Change function/variable name in code files
Post by: Ashmoor on July 14, 2018, 03:53:21
How do you guys handle changing a function name or a variable name?  For example if I have a type that's called TTextBox that has a function TCreateTextBox and I want to rename that function to TCreateChildTextBox, I have no idea where I'm calling it in the code to rename it everywhere and even worse, there are other types having a function with the same name, so a basic replace all does not work. Is there a simple procedure or just try to build and fix the resulting errors?

I am using blide, maybe it has a shortcut to handle that?
Title: Re: Change function/variable name in code files
Post by: Scaremonger on July 14, 2018, 13:30:07
Hi,
I would usually open the offending file and anything I know that is using it in Notepad++ and use a simple search to locate potential matches. I would only press replace when I know that it is the correct one and not calls to the other type.

Notepad++ has a regex search option too, which might help to identify the correct ones to replace.

Or maybe you could rename your function/method and replace the old name with a dummy function containing a simple "debugstop": Run your code and every time it stops, follow it back to the call and update your code. Once you've got all the calls, you can remove the dummy function. An alternative to this might be to put an "assert" in your dummy function which will cause a runtime error and you can trace the error from there.

Otherwise you may need to just change the function in your type and as you suggested and let the compiler find the mismatches for you.
Title: Re: Change function/variable name in code files
Post by: Ashmoor on July 15, 2018, 04:05:06
Thanks, the dummy function idea is great! I didn't think about opening bmax files in notepad++ but it makes perfect sense with the high quality find/replace tools there.