CSC/ECE 517 Fall 2013/ch1 1w07 d: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
Line 10: Line 10:
In general, complexity is a measure of the number of branches and paths in the code.
In general, complexity is a measure of the number of branches and paths in the code.


Cyclomatic complexity, in particular, is a popular metric for measuring such complexity.  In its simplest form, it can be thought of as adding 1 to the number of decision points within the code. <ref></ref>
Cyclomatic complexity, in particular, is a popular metric for measuring such complexity.  In its simplest form, it can be thought of as adding 1 to the number of decision points within the code. <ref>{{cite web | url= http://www.codeproject.com/Articles/13212/Code-Metrics-Code-Smells-and-Refactoring-in-Practi}}</ref>


<pre>
<pre>
Line 32: Line 32:


==References==
==References==
<ref>{{cite web | url= http://www.codeproject.com/Articles/13212/Code-Metrics-Code-Smells-and-Refactoring-in-Practi}}</ref>

Revision as of 15:04, 18 September 2013

Background

The practice of code refactoring deals with changing the content or structure of code without changing the code's function in its execution. Code refactoring has become a standard programming practice, as it potentially promotes readability, extensibility, and reusability of code.

Whether done through an IDE or by hand, large-scale code projects can prove tedious to refactor. If minimal non-functional benefits are achieved through refactoring, time is wasted. Furthermore, if not done properly, code refactoring can actually break the functionality of the code.

Metrics

There are a variety of metrics that are used to quantify the merits of refactoring.

Complexity

In general, complexity is a measure of the number of branches and paths in the code.

Cyclomatic complexity, in particular, is a popular metric for measuring such complexity. In its simplest form, it can be thought of as adding 1 to the number of decision points within the code. <ref></ref>

public void makeDecision(condition) {
  if(condition a) {
    choose(a);
  }
  else {
    choose(b);
  }
}

In this example, there are two decision points, so the cyclomatic complexity is 2+1=3.

Lines of Code

Change Over Time

Duplication

References