Author Topic: How about refactor?  (Read 13190 times)

bluekylin

  • Guest
How about refactor?
« on: July 30, 2005, 06:16:33 am »
Is there a plan to implement refactor? like as the refactor of eclipse

Offline Urxae

  • Regular
  • ***
  • Posts: 376
Re: How about refactor?
« Reply #1 on: July 30, 2005, 11:57:00 am »
Sounds like a very good idea for a plugin :). Unfortunately as far as I know nobody is working on this :(.
I'd sure like someone to take up the task though, I really love the Java refactorings in Eclipse and would certainly be interested in a plugin for Code::Blocks that implemented something similar for C++.
Unfortunately, the fact that C++ has a preprocessor will probably make refactoring for it more difficult to implement as fully as possible for Java. I think implementing it the same way Eclipse does will be very difficult, as that would entail implementing a dynamic syntax tree of the files being edited (scratch that, of everything that uses anything declared in it even). Which requires a dynamic standards-compliant preprocessor and parser for C++ (one of the more difficult languages to parse fully).
However, a more limited form may be possible by ignoring preprocessing (or at least the more advanced uses of it) and not parsing expressions fully, but just enough to recognize what elements it contains (for instance, operator precedence probably doesn't matter much, but things like function calls are easily recognizable and handy for things like renaming said functions).

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: How about refactor?
« Reply #2 on: August 01, 2005, 05:48:16 pm »
Sounds like a very good idea for a plugin :). Unfortunately as far as I know nobody is working on this :(

Maybe because of the very few people around, nobody has the slightest idea of what refactoring is? :P

Offline David Perfors

  • Developer
  • Lives here!
  • *****
  • Posts: 560
Re: How about refactor?
« Reply #3 on: August 01, 2005, 05:52:39 pm »
No I don't know for sure what is is... ;) And I have used Eclipse for a long time...
OS: winXP
Compiler: mingw
IDE: Code::Blocks SVN WX: 2.8.4 Wish list: faster code completion, easier debugging, refactoring

Offline squizzz

  • Almost regular
  • **
  • Posts: 132
Re: How about refactor?
« Reply #4 on: August 01, 2005, 06:00:27 pm »
Refactoring is basically process of cleaning up existing source code in order to make it... well... better, more clearly written (easier to mantain, expand, have more potential, etc).

However, I have no idea how plugin could effectively aid this quest. (Did anyone make such a thing ever work?)
Any ideas? :)


Btw: Wikipedia says: Code refactoring.
« Last Edit: August 01, 2005, 06:14:20 pm by squizzz »
this space is for rent

Offline Urxae

  • Regular
  • ***
  • Posts: 376
Re: How about refactor?
« Reply #5 on: August 01, 2005, 06:26:26 pm »
Maybe because of the very few people around, nobody has the slightest idea of what refactoring is? :P

Short version: Refactoring is changing the code without changing the functionality. (Usually done to clean up the code)

Some examples:
  • Moving a method or field to a base class from a derived class
  • Putting some code in a separate function
  • Replacing all calls to a function by inlined versions of that function (reverse of above)
  • Renaming something. A class, variable, function, typedef, whatever.
  • Encapsulating a field: make a public field private and add accessors (GetXXX/SetXXX).
  • Reorder the parameters of a function, both in declaration/definition and in all calls.
  • Add a parameter to a function, and automatically update all calls to it by putting in some default value for it.

There are more possible refactorings. The above-linked wikipedia article has a list of some of them (mostly just their names though).
They're usually well-defined and perfectly doable by a program, provided it has a syntax tree to work on. Not sure how easy this is without actually parsing to full C++ syntax trees.

However, I have no idea how plugin could effectively aid this quest. (Did anyone make such a thing ever work?)
Any ideas? :)

Well, they implemented it for Java programs in Eclipse. Java has a much easier to parse syntax though, and Eclipse maintains an abstract syntax tree on the fly for Java programs. Pretty easy to use, too. Just right-click a relevant piece of code (usually an identifier or selection) -> Refactor (IIRC) -> <name of refactoring>. It pops up a dialog for any specific choices you need to make (new name of field/function, new order of parameters, etc.). Then just click OK and it does it all for you ;).

Unfortunately, for C++ it'll probably be more difficult because of the grammar from hell (to parse).

bluekylin

  • Guest
Re: How about refactor?
« Reply #6 on: August 02, 2005, 05:57:17 am »
Sounds like a very good idea for a plugin :). Unfortunately as far as I know nobody is working on this :(.
I'd sure like someone to take up the task though, I really love the Java refactorings in Eclipse and would certainly be interested in a plugin for Code::Blocks that implemented something similar for C++.
Unfortunately, the fact that C++ has a preprocessor will probably make refactoring for it more difficult to implement as fully as possible for Java. I think implementing it the same way Eclipse does will be very difficult, as that would entail implementing a dynamic syntax tree of the files being edited (scratch that, of everything that uses anything declared in it even). Which requires a dynamic standards-compliant preprocessor and parser for C++ (one of the more difficult languages to parse fully).
However, a more limited form may be possible by ignoring preprocessing (or at least the more advanced uses of it) and not parsing expressions fully, but just enough to recognize what elements it contains (for instance, operator precedence probably doesn't matter much, but things like function calls are easily recognizable and handy for things like renaming said functions).
   Yes, refactor must need the support of compiler. And we know, the refactor need the correct code, at least which can be compiled success :). So we can use the preprocessor and parser of compiler to gather info we need. But, I don't know whether there is such a compiler. how about gcc?

Offline Funto

  • Multiple posting newcomer
  • *
  • Posts: 81
Re: How about refactor?
« Reply #7 on: August 02, 2005, 02:43:48 pm »
Maybe should we take a look at Bison?

bluekylin

  • Guest
Re: How about refactor?
« Reply #8 on: August 03, 2005, 06:02:06 am »
 Bison? How about boost::spirit?
The macro maybe a nightmare!

Offline tuft

  • Single posting newcomer
  • *
  • Posts: 9
Re: How about refactor?
« Reply #9 on: September 24, 2005, 08:17:28 pm »
How about using code from CPPRefactory, it's open source.
http://sourceforge.net/projects/cpptool