Use simian to check redundant code

Source: Internet
Author: User
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"

    • Check all C # files:

"*. 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.