Sunday, January 25, 2009

Sequence Points

Sequence points map between IL (intermediate language) and C# source elements. A statement in C# may be implemented by several IL instructions. Several of these IL instructions may map to a single native instruction. They are essential for supporting source-level debugging as explained here.
NDepend uses sequence points to compute lines of code as explained here.
NCover uses sequence points to determine code coverage.

Sunday, January 11, 2009

Cyclomatic complexity - class vs method level? Chidamber & K

Cyclomatic complexity is useful to look at the method level. At the class level it mayb e useful to look at the sum of CC's of all the methods in the class - this is a different measure referred to as Weighted Method per Class.

This is a good article that looks at cyclomatic complexity of methods in a codebase developed using TDD approach.

This article looks at the correlation between defects and complexity measures.

The Chidamber & Kemerer metrics are worth taking a look at:
- WMC: Weighted methods per class
- DIT: Depth of Inheritance Tree
- NOC: Number of Children
- CBO: Coupling between object classes
- RFC: Response for a Class
- LCOM: Lack of cohesion in methods

Sunday, January 4, 2009

RhinoMocks Constraints with IsMatching() using Predicate

var mocks = new MockRepository();
var repository = mocks.StrictMock();
var controller = new AController(repository);
List items = new List {"foo"};
var modelObj = new ModelObj(items);

Predicate compareModelObjs =
delegate(ModelObj m) { return m.Items.AsEnumerable().SequenceEqual(items); }

repository.Expect(r => r.SaveModelObj(null)).Constraints(Is.Matching(compareModelObjs)).Return(true);
mocks.ReplayAll();
controller.Save(items);
mocks.VerifyAll();

Of course, you should probably write an Equals() method on the ModelObj.