文章目录
- 前言
- cloc
- 安装
- 使用
- Simian
- 安装
- 使用
前言
关于代码重构有很多书籍,理论和工具。准备开个系列边学习边分享。
这次先学习和介绍两个比较简单的工具。
cloc
cloc counts blank lines, comment lines, and physical lines of source code in many programming languages.
cloc主要用于统计代码行数,会统计空格、注释和我们工程中,各项代码的分布情况。显示效果如下:

repo地址:
https://github.com/AlDanial/cloc
安装
release 地址
https://github.com/AlDanial/cloc/releases/tag/1.88
mac可以使用brew安装
brew install cloc
使用
统计文件夹
cloc ./
统计文件
cloc hello.c
git repo的某次提交
prompt> git clone http://git.tiker.net/trees/pudb.gitprompt> cd pudbprompt> cloc 6be804e07a5db
更多信息参考
https://github.com/AlDanial/cloc#quick-start-
Simian
Simian (Similarity Analyser) identifies duplication in Java, C#, C, C++, COBOL, Ruby, JSP, ASP, HTML, XML, Visual Basic, Groovy source code and even plain text files. In fact, simian can be used on any human readable files such as ini files, deployment descriptors, you name it.
Simian用于检查Java, C#, C, C++, COBOL, Ruby, JSP, ASP, HTML, XML, Visual Basic, Groovy代码中的重复部分(对于其他文字也同样适用)。基于行的代码匹配,不涉及到语义层面。所以检查出来的代码就是完全重复的。对去除重复代码有一定的帮助。
对于开源或者非商业用途,是可以免费使用的。
A Personal/SOHO License for Simian is US$99.
A project/build server license for Simian is US$499 and entitles you to use Simian on any number of machines solely for the licensed project, or on a single machine for many projects.
安装
下载界面
http://www.harukizaemon.com/simian/get_it_now.html
使用
举例如下:
/d/simian-2.5.10/bin/simian-2.5.10.exe -includes="C:\projects\my-projects\**\*.cs" -threshold=5 -formatter=xml:d:/simian5_cs.xml
-includes 指定了需要检测的文件内容
***.cs表示检测文件夹中所有的cs文件
-threshold指定了重复的行数阈值
-formatter指定了输出的文件
输出的xml文件会指出哪些文件的哪些行会有重复,最后有一个统计数据。















