Thursday, November 4, 2010

Code Correctness and Smart Tools for .Net developers

Code Correctness and Smart Tools for .Net developers - Dino Esposito

    Testability is the capability of a system to be tested (especially in an automated way)  Created a Design-for-Testability. Three things that define testability: Visibility, Control, Simplicity.  .Net 4 instantiates Code Contracts to try and meet this,  And some tool to help check Rewriter, and Static Checker.  Rewriter, rewrites your code, adding checks into it.  Three basic types of code contracts are: PreConditions, Postconditions, Invariants.  Contracts must be specified in the body of methods.  Can have different code contract per build type. Contracts are plain code, playing a declarative role, like attribute, but more expressive.
    These Contract codes asserts are disabled in release builds. Use Requires method to check for PreConditions.  Contract.Requires statements are run in order listed, and must be run before any other code is run.  Use Contract.ContractFailed method to customize messages.  Use Ensures or EnsuresOnThrow Method for post condition checks. Use Invariants method to check invariants, these must all be defined for a class in one place. Will use the contractInvariantMethod attribute on any method you want to check for invariants.
    These seem like they could add a bit more code writing to implement,  and should be researched more before we would think about implementing it.

No comments:

Post a Comment