Author Topic: Feature : dynamically rename a variable  (Read 27753 times)

sleli

  • Guest
Feature : dynamically rename a variable
« 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

Offline rcoll

  • Almost regular
  • **
  • Posts: 150
Re: Feature : dynamically rename a variable
« Reply #1 on: September 11, 2008, 07:47:55 pm »
Did you try the "Replace in Files" function under the "Search" menu?

Ringo

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Feature : dynamically rename a variable
« Reply #2 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.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Jan van den Borst

  • Multiple posting newcomer
  • *
  • Posts: 99
Re: Feature : dynamically rename a variable
« Reply #3 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

Offline rcoll

  • Almost regular
  • **
  • Posts: 150
Re: Feature : dynamically rename a variable
« Reply #4 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

Offline dje

  • Lives here!
  • ****
  • Posts: 683
Re: Feature : dynamically rename a variable
« Reply #5 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

Offline rcoll

  • Almost regular
  • **
  • Posts: 150
Re: Feature : dynamically rename a variable
« Reply #6 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