🔒 Locked
Refactoring
Advertisement
Original Post
Hi,
I''m wondering who is using Refactoring (www.refactoring.com) to clean-up and reorganize his code. I want to use it for my code which became quite big (70''000 lines), but I don''t know where to begin or what tools are best suited for that purpose.
I am using MVC++.
Are by chance some basic refactoring functionalities included in MVC++6?
My major need is when I want to rename a function NAME of class CLASS: now I have to go through all occurences of NAME in all my files, check if it belongs to CLASS, then manually rename each occurence. This can easily take one hour for a single function!!!
Or when I want to replace a public variable VARIABLE with two function GETVARIABLE and SETVARIABLE...
Thanks
quote:
Original post by MrFreeze
My major need is when I want to rename a function NAME of class CLASS: now I have to go through all occurences of NAME in all my files, check if it belongs to CLASS, then manually rename each occurence. This can easily take one hour for a single function!!!
1) Ctrl+R (or some equivalent for Replace)
2) Replace what: "TClass::FunctionName" or whetever
3) With what: "TNewClass::NewFunctionName" or whatever
Repeat steps 1 - 3 for all different occurences of the name. Use the compiler''s help to find out what and where to replace (compile the project and it''ll take you to the line containing the old code - this is nasty, but faster than searhing in my experience)
Things to keep in mind to make this process easier:
1) Write code smartly - do not use fancy and cryptic names, but try to be consistent between different functions (eg always use the iterator name ''i'' if possible)
2) Do not create senselessly small files containing only one function, making the total number of files large
3) Name the functions and classes properly as you create them so that there will be no need for refactoring. I know you can''t always do that, but I myself haven''t had to change any names on a massive scale for quite some time now.
4) Think your code through - this will lead to less duplication of code - a problem any programmer has, especially if he is still a beginner. I know I write duplicate code in some places - usually totally unknowingly.
5) Make backups - Replace can wreck your code beyond all repair!
6*) As far as I figure refactoring has to keep track of your code which means that it must contain a "code analyzer" embedded in the IDE (or some other exocompiler component) - much like the one available in VC that keeps the structure of your code in memory rather than simply displays the text and keeps track of the project file(s). This is something most IDE''s don''t support and IMO is potentally unsafe if made available - imagine renaming something you are not completely aware of (out of absent mindedness?) and later on trying to figure out what you have done to your code with a flick of the wrist. If you decide to spend that hour on renaming stuff you can at least be sure you teach yourself the lesson of knowing what you''re doing to your code...
Just my ruminations based on using a "menial" compiler (BC5.02 - which I truly and completely love) rather than the Microsoft thing-thingy...
Crispy
quote:
Original post by Crispy
1) Ctrl+R (or some equivalent for Replace)
2) Replace what: "TClass::FunctionName" or whetever
3) With what: "TNewClass::NewFunctionName" or whatever
Repeat steps 1 - 3 for all different occurences of the name.
That is not at all like a code-aware refactoring browser. Ideally, a good refactoring browser should maintain an internal data structure of the entities that make up the project, and allow transforms to be performed on that data structure. For example, you might have a node within the structure which represents a particular class, with attributes that record source-level meta-information such as "name". This class might be referenced from multiple points in the project. If you then change the name of the class, the browser already knows each node that has to change in line with the new name. This is nothing like the tedious and error-prone process of having to write a potentially complicated regex matcher, or even partial source-code parser, running it across your project, and then manually filtering the results list, eventually going back and changing the source wherever a positive match is identified.
quote:
Original post by civguy
Many Java IDEs have automatic refactoring tools. IDEA has the best ones. That''s probably because the language is simpler and more consistent, so it''s easier to make refactoring tools for it.
I haven''t found any refactoring tools for C++ either..
That''s because IDEa is one of the (if not the) best IDE''s around, especially when it comes to refactoring.
quote:
Original post by civguy
I haven''t found any refactoring tools for C++ either..
This is probably due to the same reason that there is no Intellisense(-like functionality) that really works for C++.
"I know very well who Satan is: He is freedom. He is the uncontrolled, the incalculable, the antithesis of order and discipline, the antithesis of the legalism of outer space.... We know where a planet will be in twelve years, four months and nine days. But we don''t know where a butterfly will have flown one minute hence. Therefore the butterfly is of Satan."
-- Jens Bjørneboe
quote:
This is probably due to the same reason that there is no Intellisense(-like functionality) that really works for C++.
whole tomato works perfectly well
Perfectly? Hardly.
"I know very well who Satan is: He is freedom. He is the uncontrolled, the incalculable, the antithesis of order and discipline, the antithesis of the legalism of outer space.... We know where a planet will be in twelve years, four months and nine days. But we don''t know where a butterfly will have flown one minute hence. Therefore the butterfly is of Satan."
-- Jens Bjørneboe
"I know very well who Satan is: He is freedom. He is the uncontrolled, the incalculable, the antithesis of order and discipline, the antithesis of the legalism of outer space.... We know where a planet will be in twelve years, four months and nine days. But we don''t know where a butterfly will have flown one minute hence. Therefore the butterfly is of Satan."
-- Jens Bjørneboe
quote:
Original post by SabreMan
That is not at all like a code-aware refactoring browser.
Granted. I didn''t say it contains a refactoring browser because it doesn''t. Therefore it is only natural that I do everything the way I described. But I''ve grown used to it and it doesn''t really bother me. How do you refactor your code if need be?
quote:
Ideally, a good refactoring browser should maintain an internal data structure of the entities that make up the project ... If you then change the name of the class, the browser already knows each node that has to change in line with the new name.
Afaik VC6 does that (probably earlier versions as well though I''m not sure) and this is basically what I described in my previous post (that the existence of such a solution would be great). Unfortunately we don''t live in an ideal world.
quote:
This is nothing like the tedious and error-prone process of having to write a potentially complicated regex matcher, or even partial source-code parser, running it across your project, and then manually filtering the results list, eventually going back and changing the source wherever a positive match is identified.
I''m sorry for being stubborn, but doesn''t it take all that to scan in the structure of the project - you still need to create an extensive tree of all the objects in the program independently from the compiler. Since no IDE I know supports refactoring on this level, doesn''t that mean going through "the tedious and error-prone process of having to write a potentially complicated regex matcher ...".
Crispy
quote:
Original post by Crispy
Granted. I didn''t say it contains a refactoring browser because it doesn''t.
And neither did I say you made that claim. I pointed out the difference between manual and automated approaches, and explained why a manual approach is tedious.
quote:
How do you refactor your code if need be?
What does that have to do with it?
quote:
Afaik VC6 does that (probably earlier versions as well though I''m not sure)
VC6 doesn''t do what I described, if that''s what you''re referring to.
quote:
I''m sorry for being stubborn, but doesn''t it take all that to scan in the structure of the project
It depends how the problem is approached. With C++, any such tools are are going to have problems due to the utter lack of introspective capabilities.
quote:
Since no IDE I know supports refactoring on this level, doesn''t that mean going through "the tedious and error-prone process of having to write a potentially complicated regex matcher ...".
Refactoring IDEs support this idea to some level or another. I''m led to believe Smalltalk has had good refactoring browsers for some time. It''s quite possible that we''ll see more and more good refactoring browsers appear in the near future, particularly as dynamic languages gain popularity.
quote:
Original post by SabreMan
What does that have to do with it?
Just interested how you handle the problem. Nothing too political...
quote:
VC6 doesn''t do what I described, if that''s what you''re referring to.
My bad, I was partly speculating and under the impression it did.
quote:
It depends how the problem is approached. With C++, any such tools are are going to have problems due to the utter lack of introspective capabilities.
Why is that neccessary? This can be done "mechanically" since an object is "logically discrete", meaning that it is unique in its scope of declaration/definition. The first (and only) thing that could be a source of further problems, that pops to my mind at the first glance, is namespace clashes. Everything else should be easily automatable.
quote:
Refactoring IDEs support this idea to some level or another. I''m led to believe Smalltalk has had good refactoring browsers for some time. It''s quite possible that we''ll see more and more good refactoring browsers appear in the near future, particularly as dynamic languages gain popularity.
Possible - I have no experience in this category.
Crispy
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement