I've been trying to think of something that drastically change how I coded. Bugs and productivity really are the two major dragons to slay.<p>I'm just spitballing here but something I'd really like to see stuff like code contracts and unit testing, but more integrated with the language, less verbose and requiring less to setup. Being able to let the "meat" of a method be separated from all the error-checking, post, pre conditions etc would really make things cleaner.<p>Current implementation feels like it requires too much setup with separate classes, duplicate method signatures in several places etc etc. It would be really cool to have something like<p><pre><code> public int SomeMethod(int a, int b)
pre
{
Requires (a > 5);
Requires (b >= 0, new Exception("something something"));
}
{
// DoStuffHere
}
post
{
Ensures (result > 0, new Exception("needs to be above 0"));
}
</code></pre>
I'd even want to be able to separate it into separate files using partial classes (or something) so you could the condition stuff separate , with or without duplicating signature
depending if you wanted to target specific overloads<p>Full signature would simply be without the body:<p><pre><code> public int SomeMethod(int a, int b)
pre
{
Requires (a > 5);
Requires (b >= 0 ,new Exception("something something"));
}
post
{
Ensures (result > 0);
}
</code></pre>
Without signature is trickier, but would be cool since you could use same conditions for several overloads, and just target the variables that are included in each:<p><pre><code> Conditions.SomeMethod
{
pre
{
Requires (a > 5);
Requires (b >= 0, new Exception("something something"));
}
post
{
Ensures (result > 0);
}
}
</code></pre>
heck, why not even throw in "test blocks" and Visual studio could run light-weight kind of unit test as you programmed and mark the whole method as functioning or not. Imagine having a sort method and throw in something like:<p><pre><code> public IEnumerable<int> Sort (IEnumerable<int> list, Order order)
test
{
(list = {3,5,6,2}, order = Order.Ascending) => result == {2,3,5,6};
(list = {3,5,6,2}, order = Order.Descending) => result == {6,5,3,2}
}
</code></pre>
VS could highlight the failed test(s) directly in the editor as you coded<p>The specifics and syntaxes of these things requires some thought but I love the basic premise, am I rambling?<p>edit: I saw that something in this direction if not as extensive was actually discussed