|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionThe goal of this tool is to check an ASP project/folder for unused code elements. These elements include unused constants, global variables, functions, subs, and local variables. This comes in very handy if you undertake large changes in a project, or use include files from previous ASP projects and want to be sure, that you do not deploy unnecessary code. This article will not describe in detail how the code works, since the main topic is how to get rid of unused elements, and the code is actually written in C#. It will, however, give you an understanding of how the tool operates and what its limitations are. Using the analyzerThe ASP Code Analyzer is very easy to use. First download the executable, unzip it and run ASPCodeAnalyzer.exe. Next you can browse for the directory that contains your ASP project. Hit the 'Go' button and the analyzer will do its work. I would like to stress on the point that the analyzer will not change your files. It will merely point to the portions in your code where there are unused code elements. If you have UltraEdit32 installed in your machine and if you double click on the findings list, the tool will automatically start UltraEdit32 and open the file on the corresponding code line. If you use a different editor, you can use the File/Options dialog to define your editor and the parameters used to open a specified file on a given line. Your code has to be syntactically correct. Otherwise the analyzer will not work properly. How the analyzer operatesPass one
Pass twoNow for the tricky part: Finding unused global variables and subs/functions.
By examining file groups instead of files, an include file is tested in all possible contexts. Matching the elements against the codeLet's say the analyzer wants to know if the sub call WriteTd( someVar)
call WriteTd ( someVar)
The following statements do not match, since the sub's name is actually just a part of the whole identifier: call WriteTd2( someVar)
call MyWriteTd( someVar)
LimitationsBe warned: Due to it's heuristic nature, the algorithm is probably not able to find all the unused elements in your code. On the positive side all its findings should really be unused elements. The analyzer is unable to detected the following: function test
dim unusedVar
unusedVar = 12
end function
Although the variable Also, if you use local variables that shadow global variables the global variables are always considered used. dim unusedGlobal
function test
dim unusedGlobal ' Shadows the global variable
unusedGlobal = 12
Response.Write( unusedGlobal)
end function
Variables should not be defined in more than one line. In the following code: dim a,b,c, _
d,e,f
the analyzer will only identify ConclusionDespite its shortcomings the ASP Code Analyzer should give you a good impression on how clean your code actually is. History
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||