|
I have learned how to refactor. Code One of the highlights is "code redundancy". When we write code, we will inadvertently copy and paste the code. Program Is filled with this large amount of repeated code. Recently, during the reconstruction of my previous code, I found a useful tool to check the redundant code. This software is called "simian ", the current version is 2.2.12, which is not only C # code, but can also be used to check C, C ++, COBOL, Ruby, JSP, ASP, HTML, XML, Visual Basic and other format code. (The monkey on the left is the simian logo, but it seems to be an orangutan ;)) FirstWe will download the latest version from the official site. Note that simian is not a free tool. If you use it to checkSource codeOr non-commercial code, it is free to use, if it is a commercial application, you need to pay. After the download is complete,Decompress the file,Add the path of simian to the path of the Windows environment variable, At the same time,Change the file name of simian-2.2.12.exeto simian.exe.In this way, we can use simian as a command line tool. Run simian in cmd:
C: \> simian.exe [Options] files
The following describes the specificUsage:
- Check all C # files in subdirectories:
"-Recurse = *. cs"
- Check all the C # files in the current directory, and only check the repeated code with more than three lines of code.
-Threshold = 3 "*. cs"
"*. Cs" Example:
- There is a file named sample. CS under c: \ project \ SRC. to check whether redundant code exists in the file, the command line is as follows:
C: \ project \ SRC> simian "sample. cs"
- To check all Cs files under c: \ project \ SRC, including redundant code in sub-directories, run the following command:
C: \ project \ SRC> simian "-recurse = *. cs" here is a preliminary introduction to Simian. Because it is a command line, the output information does not look very intuitive, if you view the results directly from the command, it will be very painful, but fortunately, the plug-in has been integrated into eclipse, and in the DOTNET camp, if you use sharpdevelop as a development tool, you can use a small plug-in I wrote. This plug-in can intuitively view the simian output results. Next, I will also introduce this plug-in the Article . (end) |