Is there a standard way to count statements in C #

I was looking for some code length metrics other than lines of code. Something that Source Monitor reports is statements. This seemed like a valuable thing to us, but, as the Monitor source calculated, some things seemed unintuitive. For example, a for statement is one statement, although it does contain a variable definition, a condition, and an increment statement. And if a method call is nested in an argument list to another method, all this is considered one of the statements.

Is there a standard way to record statements and their rules governing such a thing?

+3
source share
4 answers

" " #. , .

, / , , , , ?

: " " 2500, 1500 150, , ; 2480, 1620 174, .

, , - NDepend, 100%, . - NDepend 82 , Cyclomatic Complexity.

+5

: " , ". , . , , , .

, , "" , , , .

http://en.wikipedia.org/wiki/Cyclomatic_complexity

UPDATE: Re:

, " " - . , ( "" , , , , ), " " , "" .

, , , , . " ", , , , .

: , " ". # , "" , , , . :

  void M()
  {
    try
    {
      if (blah)
      {
        Frob();
        Blob();
      }
    }
    catch(Exception ex)
    { /* eat it */ }
    finally
    {
      Grob();
    }
  }

M? , M , try-catch-finally. ? try , "if". "if" - , . . , . catch - catch , - , , !

, ? , , "", , , . , , .

+7

# ( "", "" ) .., # BNF . (, #, , , SLOC , ).

, ( ), . , , , . "173,92" ; "81.02", , , , , , .

, ; "81.02", "173,92", , ?

You can also consider the relationship of structural metrics (such as Cyclomatic) to SLOC as an indication of β€œtoo much,” or at least an indication of code that is too tight to understand

+3
source

One simple metric is to simply count the punctuation marks ( ;, ,, .) between tokens (to avoid errors in lines, comments or numbers). Thus, for (x = 0, y = 1; x < foo.Count; x++, y++) bar[y] = foo[x];6 will be considered.

+1
source

Source: https://habr.com/ru/post/1734731/


All Articles