taiwo taiwo

Niner since 2008


  • Pex - Automated Exploratory Testing for .NET

    Why can't constraints be constructs that can be applied on the class and methods and automatically enforced on the caller by the framework? That is, one should be able to decorate a method with:

    [Pre-Constraint: i>=1, i<=int.MaxValue, c!=null]
    [Post-Constraint: i==i, c==c]

    //Pre-constraint indicates value of i accepted from caller must be greater or equal to 1; and that c cannot be null.
    //Post-Constraint imply that on method exit the constraints should also be respected otherwise the method cannot successfully complete - constraint exception condition

    The above constraint would be enforced on calling code at design or compile time (if a known value or a variable whose value is known is being passed). The constraint on class instances being used in a method should then be passed up the chain to all callers. This would at least reduce a lot of run-time time issues since the constraints are enforced at design or compile time.

    In fact the i<=int.MaxValue constraint would be superfluous if int already defines constraint on acceptable values of between MinValue and MaxValue.