Answer the question
In order to leave comments, you need to log in
Cleaning up Delphi code?
There is a large (several hundred thousand lines) project in Delphi that has been in development for about 10 years.
I believe that more than a dozen developers worked on it. Consequently, there you can see all sorts of manifestations of human stupidity, negligence, curvature and other unpleasant things.
I would like to comb this project a little, and automate this process as much as possible (because manually it can take more than one week). Namely:
- remove commented blocks of code
- remove code that is not linked into the executable
- remove unused uses
- remove pas / dfm files that do not belong to the project
- so that all previous actions are completely controlled
Well, various other goodies are also desirable, such as formatting the code according to a template, identifying potentially dangerous or simply suspicious places, etc. But cleaning the code (the above points) is a priority.
Answer the question
In order to leave comments, you need to log in
It won't work automatically.
Uses can not be deleted, starting with delphi 6, unnecessary ones are not connected.
Pas / dfm I deleted manually, everything that was not in the project file - then I returned the necessary ones.
I don’t advise formatting to one view - then it’s very difficult to compare changes.
It is better with pens, it is written quickly, you can adjust it optimally for yourself. It is better to use ready-made engines / components for parsing delphi code (there are many of them, many are available without problems) and convenient control in the future. Look at torry.net.
Although there are a number of non-trivial tasks (for example, coverage assessment), which are better solved with ready-made tools (for example, the AQTime trial), in order to save time. Although this can be solved by yourself.
But after a couple of days, you will get a solution, which, IMHO, is not ashamed to post in public and help many in the future :)
But because it was necessary to use VCS. And in general ... The current state of Delphi resembles the "convulsions of a dying rhino" (c)
Refactoring a large project can drag on for many months, do you need it? Can only refactor potentially buggy, slow sections, in order to visually optimize the work?
For formatting, I advise GExperts (Experimental).
For everything else, CnPack Wizards should be fine.
For formatting, it's better to use DelForEx, as
far as I remember, cleaning of uses is possible in CnPack
, but deleting commented code is easy to do with any editor that supports regular expressions. For example, use a search in GExperts for \(\*.*\*\) and when the results appear, replace it with an empty string (there is a replace all items item),
it is best to remove unused code with specialized software. AQTime was already given here above, I can also advise Pascal Analyzer
but in general, refactoring is a long, tedious and difficult to automate task
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question