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 25, 2009
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
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.
var repository = mocks.StrictMock
var controller = new AController(repository);
List
var modelObj = new ModelObj(items);
Predicate
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.
Monday, December 22, 2008
LINQ-to-SQL: DataContext.SubmitChanges() throws ChangeConflictException if NOCOUNT is ON
DataContext.SubmitChanges() will throw a ChangeConflictException if NOCOUNT is on. Use Reflector to look at the code in System.Data.Linq, you will notice that ChangeProcessor.SubmitChanges() method uses the count of the number of rows affected by the SQL statement to determine if updates succeeded. Updates are setup to fail if the row being updated was deleted or modified concurrently by another user. For example, say your update had modified value for column C in table T in the row with primary key PK = 1 from 5 to 6. The update statement constructed by Linq will look something like:
update T set C=6 where PK=1 and C = 5
The update will return 0 rows affected when either the row was deleted by a different user or if the value of C was updated. In either case, LINQ will raise a ChangeConflictException. However, if NOCOUNT is on, then the update statement will always return 0. Hence LINQ throws the ChangeConflictException even if there is no conflict.
update T set C=6 where PK=1 and C = 5
The update will return 0 rows affected when either the row was deleted by a different user or if the value of C was updated. In either case, LINQ will raise a ChangeConflictException. However, if NOCOUNT is on, then the update statement will always return 0. Hence LINQ throws the ChangeConflictException even if there is no conflict.
Subscribe to:
Posts (Atom)