有没有一种标准的方法来计数C#中的语句 [英] Is there a standard way to count statements in C#

查看:94
本文介绍了有没有一种标准的方法来计数C#中的语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看代码行以外的一些代码长度指标. Source Monitor报告的内容是语句.这似乎是一件很有价值的事情,但是Source Monitor计算某些事情的方式似乎并不直观.例如,for语句是一个语句,即使它包含变量定义,条件和增量语句.而且,如果将一个方法调用嵌套在另一个方法的参数列表中,则整个过程都被视为一个语句.

I was looking at some code length metrics other than Lines of Code. Something that Source Monitor reports is statements. This seemed like a valuable thing to know, but the way Source Monitor counted some things seemed unintuitive. For example, a for statement is one statement, even though it contains a variable definition, a condition, and an increment statement. And if a method call is nested in an argument list to another method, the whole thing is considered one statement.

是否有一种标准的方式来对语句进行计数,并且它们的规则控制着这种事情?

Is there a standard way that statements are counted and are their rules governing such a thing?

推荐答案

您可能最接近什么是语句"的正式定义的是

The closest you might get to a formal definition of "what is a statement" would be the C# specification itself. Good luck working out whether a particular tool's measurement agrees with your reading of the specification.

鉴于度量标准最好用作更好/更糟糕的代码的指南,而不是严格的公式,该工具使用的确切定义是否有很大不同?

Given that metrics are best used as a guide to better/worse code, and not a strict formula, does the exact definition used by the tool make much difference?

如果我有三种方法,语句长度"分别为2500、1500和150,那么我知道我将首先检查哪种方法.另一个工具可能报告2480、1620和174不太重要.

If I have three methods, with "statement lengths" of 2500, 1500 and 150, I know which method I'll be examining first; that another tool might report 2480, 1620 and 174 isn't too important.

NDepend 是我见过的用于度量指标的最佳工具之一. a>,尽管我也不是100%知道它在使用什么定义.根据该网站, NDepend具有82个独立的指标,其中包括循环复杂度.

One of the best tools I've seen for measuring metrics is NDepend, though again I'm not 100% sure what definitions it is using. According to the website, NDepend has 82 separate metrics, including Number of instructions and Cyclomatic Complexity.

这篇关于有没有一种标准的方法来计数C#中的语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆