Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: sleli on September 11, 2008, 11:16:23 am

Title: Feature : dynamically rename a variable
Post by: sleli on September 11, 2008, 11:16:23 am
Hello,

It should be nice I may use this feature because I have to apply coding standards upon variables, functions etc...

What I would like : Select a variable named "layer_id" and renamed it "AGS_LayerId" for example everywhere in my code. If it's a local variable, renamed it only into the appropriate function.

Is there anyway to do that efficiency with Code::Blocks ?

Thanks
Have a nice day.
Stephane
Title: Re: Feature : dynamically rename a variable
Post by: rcoll on September 11, 2008, 07:47:55 pm
Did you try the "Replace in Files" function under the "Search" menu?

Ringo
Title: Re: Feature : dynamically rename a variable
Post by: thomas on September 12, 2008, 12:01:53 pm
Interesting idea, something I'd wish to have too sometimes. Unluckily the "only inside a function" thing means that there would have to be some considerable AS built into Code::Blocks, which currently isn't the case.

So... yes, "replace in files" sure works, but it's not precisely what you want.
Title: Re: Feature : dynamically rename a variable
Post by: Jan van den Borst on September 12, 2008, 12:47:09 pm
Yes this would be very nice to have. In MS visual studio C# it can be done with refactor-->rename. The MS ide knows which vars to change and which not. Not an easy thing to implement (robustly)

Jan
Title: Re: Feature : dynamically rename a variable
Post by: rcoll on September 14, 2008, 06:47:58 am
Interesting idea, something I'd wish to have too sometimes. Unluckily the "only inside a function" thing means that there would have to be some considerable AS built into Code::Blocks, which currently isn't the case.

So... yes, "replace in files" sure works, but it's not precisely what you want.

I don't get this ... what is it exactly you would like to do?  If I want to change "MyVar" to "SomeOtherVar", then replace-in-files works perfectly fine for me.  If it's a really *really* complicated search-and-replace, I just load up an external editor that specializes in such things and do it there.  It's such a rare thing, I don't really mind doing it.

What am I not understanding?

Ringo
Title: Re: Feature : dynamically rename a variable
Post by: dje on September 14, 2008, 11:04:50 am
What am I not understanding?
Refactor->Rename means that variable scoping is taken into account, it is the most complicated thing.

Suppose you have i defined for two loops in two different functions.
Right clicking on i in a function and make Refactor->Rename on it could replace i by index for example only in the appropriate method/function, whereas the replace in files would replace any i whole word instances in all files.

Dje
Title: Re: Feature : dynamically rename a variable
Post by: rcoll on September 15, 2008, 06:17:20 pm
What am I not understanding?
Refactor->Rename means that variable scoping is taken into account, it is the most complicated thing.

Suppose you have i defined for two loops in two different functions.
Right clicking on i in a function and make Refactor->Rename on it could replace i by index for example only in the appropriate method/function, whereas the replace in files would replace any i whole word instances in all files.

Dje

Ah ... got it.  Thanks for the (very good) explanation.  I can now see where this Refactor-Rename might be usefull; although, for my uses, I would still use rename-in-files and just change "Myclass->MyVar" to "MyClass->SomeOtherVar" (but then most of my software is pretty simple and not that compilcated).

Ringo