﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-C++ &amp; Embed-随笔分类-Soft Metric</title><link>http://www.cppblog.com/KGen/category/11901.html</link><description /><language>zh-cn</language><lastBuildDate>Sat, 26 Sep 2009 23:56:09 GMT</lastBuildDate><pubDate>Sat, 26 Sep 2009 23:56:09 GMT</pubDate><ttl>60</ttl><item><title>SourceMonitor 可用于C++开发的免费代码度量工具</title><link>http://www.cppblog.com/KGen/archive/2009/09/26/97281.html</link><dc:creator>眩晕</dc:creator><author>眩晕</author><pubDate>Sat, 26 Sep 2009 05:08:00 GMT</pubDate><guid>http://www.cppblog.com/KGen/archive/2009/09/26/97281.html</guid><wfw:comment>http://www.cppblog.com/KGen/comments/97281.html</wfw:comment><comments>http://www.cppblog.com/KGen/archive/2009/09/26/97281.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/KGen/comments/commentRss/97281.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/KGen/services/trackbacks/97281.html</trackback:ping><description><![CDATA[





<div>代码度量（Code Metric)属于软件度量(Soft Metric）的范畴。很多人希望能够统计自己源码工程中的代码行数，实际上这就是Code Metric的初级形式。在很多开发标准中，都定义了Metric相关内容。如IEEE、CMM/CMMI。</div><div>Code Metric有若干重要指标。一款开源的Metric分析软件C and C++ Code Counter的分析报告书中阐述了如下指标：</div><div><br></div><div><span style="font-family: simsun; ">&nbsp;&nbsp; &nbsp;NOM = Number of modules<br>&nbsp;&nbsp; &nbsp;LOC = Lines of Code<br>&nbsp;&nbsp; &nbsp;COM = Lines of Comments<br>&nbsp;&nbsp; &nbsp;MVG = McCabe's Cyclomatic Complexity<br>&nbsp;&nbsp; &nbsp;L_C = Lines of code per line of comment<br>&nbsp;&nbsp; &nbsp;M_C = Cyclomatic Complexity per line of comment<br>&nbsp;&nbsp; &nbsp;IF4 = Information Flow measure</span></div><div><br></div><div>顾名思义，NOM是模块数量，即源码工程中包含多少模块。LOC是代码行数，这里不包括空行和注释。COM是注释行数。MVG是复杂度。L_C是每行注释代码行数，M_C是每行注释复杂度。IF4，信息流测定。（由于没有找到中文的翻译和释义，仅凭个人理解罗列翻译）</div><div>微软的VSTS2008提供Metric功能，但无法针对C++使用。CCCC(C and C++ Code Counter)似乎已经停止维护，命令行模式，不易使用。一些商用工具功能强大但过于昂贵。</div><div>SourceMonitor是一个不错的选择：<br>※免费使用<br>※Windows下GUI界面<br>※功能较为强大，可保存用于比较的基线（Baseline）<br><br><a href="http://www.campwoodsw.com/index.html" style="color: rgb(204, 0, 102); text-decoration: underline; background-color: rgb(245, 245, 245); ">http://www.campwoodsw.com/index.html</a><br><br><br></div><div>参考资料：<br><a href="http://blogs.msdn.com/fxcop/archive/2007/02/28/announcing-visual-studio-code-metrics.aspx">http://blogs.msdn.com/fxcop/archive/2007/02/28/announcing-visual-studio-code-metrics.aspx</a>&nbsp;&nbsp;C# Code Metrics<br><a href="http://en.wikipedia.org/wiki/Software_metric">http://en.wikipedia.org/wiki/Software_metric</a>&nbsp;维基百科Software Metric<br><a href="http://blog.csdn.net/summerfang/archive/2006/09/04/1176916.aspx">http://blog.csdn.net/summerfang/archive/2006/09/04/1176916.aspx</a>&nbsp;使用source monitor帮助进行代码重构&nbsp;<br><br></div><div>追记：<br>1.UTF编码的文件将不被识别和读取。CCCC和SouceMonitor都存在这个问题。SourceMonitor有相关的选项，可能是我操作问题，失败了&#8230;&#8230;<br>2.SouceMonitor统计出来的代码行数偏低。主要原因可能是没有计算大括号&#8230;&#8230; 在我目前开发的项目中，根据现有的编码规范，是否计算大括号的统计差异为40%。<br>3.适当的使用CCCC也是不错的。有些统计值CCCC较为完整。</div><img src ="http://www.cppblog.com/KGen/aggbug/97281.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/KGen/" target="_blank">眩晕</a> 2009-09-26 13:08 <a href="http://www.cppblog.com/KGen/archive/2009/09/26/97281.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>