![]() |
ubuntu.com - launchpad.net - ubuntu help
|
|
|||||||
|
Programming Talk This forum is for all programming questions. The questions do not have to be directly related to Ubuntu and any programming language is allowed. |
|
|
Thread Tools | Display Modes |
|
|
#1 | |
|
Fresh Brewed Ubuntu
![]() Join Date: Feb 2007
Location: lost
Beans: 1,259
Kubuntu
|
Code refactoring
Hi,
I'm trying to find a way to refactor code, i.e. rename a function everywhere it's used for example. I heard that Eclipse does this, but I couldn't figure out how to import a C++ project into it. And it takes up too much RAM anyway. KDevelop seems to offer refactoring according to this release announcement: Quote:
The Find-Select-Replace option is pretty helpful, but it's not real refactoring since it doesn't search&replace according to the C/C++ syntax. What code refactoring tools are available on GNU/Linux? |
|
|
|
|
|
|
#2 |
|
Ubuntu addict and loving it
![]() Join Date: Jun 2007
Location: Maryland, US
Beans: 3,962
Ubuntu 9.10 Karmic Koala
|
Re: Code refactoring
As a s/w engineer, when I hear or read the term "refactor", the first thing that comes to mind is that a s/w application needs to be modified/simplified into a similar but better, perhaps more nimble, design. Renaming functions or variables has nothing to do with refactoring.
I personally do not use any IDEs, and merely rely on 'vim'. I've been successfully using vim (and its predecessor 'vi') for over 18 years. In the next 10 years it will be interesting to see if Eclipse, KDevelop etc are still around; I'm certain that 'vim' will be. |
|
|
|
|
|
#3 |
|
Fresh Brewed Ubuntu
![]() Join Date: Feb 2007
Location: lost
Beans: 1,259
Kubuntu
|
Re: Code refactoring
Well, maybe I'll try to finish vimtutor one day.
All I can do for now is insert,search, dw, d$, yank/paste and q,q!,wq. ^^ I haven't found it to be very efficient yet. |
|
|
|
|
|
#4 |
|
Fresh Brewed Ubuntu
![]() Join Date: Feb 2007
Location: lost
Beans: 1,259
Kubuntu
|
Re: Code refactoring
I think I found something:
http://www.vim.org/scripts/script.php?script_id=2087 However, I don't know how to use it. Since you use vim, I suppose you could help me here. I copied the .vim script into a ~/.vim/plugins directory I created, but I don't understand how to use it. What's <A-r>r ? |
|
|
|
|
|
#5 |
|
Ubuntu addict and loving it
![]() Join Date: Jun 2007
Location: Maryland, US
Beans: 3,962
Ubuntu 9.10 Karmic Koala
|
Re: Code refactoring
How many files do you need to "refactor"? If it is only a few, or if they are all of a certain type, then perhaps you can use 'sed' and 'find'?
For example, to change the class name 'Foo' to 'MyClass' in this file: PHP Code:
Code:
$ sed -i s/Foo/MyClass/ Foo.cpp Code:
$ find . -name '*.cpp' -exec sed -i s/Foo/MyClass/ {} \;
|
|
|
|
|
|
#6 |
|
Fresh Brewed Ubuntu
![]() Join Date: Feb 2007
Location: lost
Beans: 1,259
Kubuntu
|
Re: Code refactoring
Yes, but that's equivalent to the Find-Select-Replace of Kdevelop. (it also accepts regular expressions)
Sometimes, things get complex like in this case if you have: FooSomething AFoo Separate word regex fails here: Foo.GetX() Foo->func() Foo(...) Somefunc(...,Foo,...) I guess if I improve my knowledge of regular expressions, I could do without a refactoring tool. For the moment, I find it easiest to change the function/class definition+prototype/methods and then compile to locate where else it's used. Most of the time, simple search&replace works well though. But not always. I thought that if Eclipse has such a function, there must be other programs offering the same. Eclipse is just too bloated and complex for me.
__________________
Tux and Gnu's travel around the world! GNU/Linux Preloaded freegamedev.net: The center of FOSS game development. iTeam: FOSS remake of GunBound -> Help wanted WebContentControl: A parental control GUI -> Help wanted Last edited by KIAaze; May 10th, 2008 at 12:17 AM.. |
|
|
|
|
|
#7 |
|
Skinny Soy Caramel Ubuntu
![]() Join Date: Jun 2007
Beans: 677
Ubuntu 9.04 Jaunty Jackalope
|
Re: Code refactoring
edit: never mind, misread the last post.
|
|
|
|
|
|
#8 | |
|
A Carafe of Ubuntu
![]() Join Date: Mar 2008
Location: Denmark
Beans: 115
Ubuntu 8.10 Intrepid Ibex
|
Re: Code refactoring
Quote:
As for tools I'm afraid I only use Eclipse, but found this site, maybe some of the links can help you? http://www.refactoring.com/tools.html
__________________
Ubuntu Intrepid Ibex (32-bit) |
|
|
|
|
|
|
#9 | |
|
Just Give Me the Beans!
![]() Join Date: May 2008
Beans: 59
Ubuntu 9.04 Jaunty Jackalope
|
Re: Code refactoring
Quote:
Refactoring DOES include renaming functions and cleaning code formatting so that code is readable, meaningful, and manageable. This is such a standard functionality and I'm really surprised KDevelop doesn't have it.. If anybody knows of any such plugin pls post. |
|
|
|
|
|
|
#10 | |
|
Dipped in Ubuntu
![]() Join Date: Jul 2008
Location: Dublin, Ireland
Beans: 591
Ubuntu 9.10 Karmic Koala
|
Re: Code refactoring
Quote:
Not really automated, and probably quite boring, but nonetheless... BTW, I have used and liked Eclipse Java refactoring and it was both useful and easy, but when I tried Eclipse (first version of CDT 4) it was unable to locate calls to templated methods, which is as much as saying that at least for those it will be impossible to refactor. |
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|