c# - Code contract ensures not proven for loop -


i'm starting play around .net code contracts (in vs2010 ultimate .net 4), try idea of static checker can , can't prove.

i'm trying following example :-

public int mult(int num1, int num2)     {         contract.requires(num2 >= 0);         contract.ensures(contract.result<int>() == (num1 * num2));         int result = 0;         (int = 0; < num2; i++)         {             result = result + num1;         }         return result;     } 

ie, simple implementation of multiply function, repeated adding.

the static checker can't verify postcondition met :-

codecontracts: ensures unproven: contract.result<int>() == (num1 * num2) 

is function not computing product correctly.. or there reason why static checker can't verify requires ? presence of loop cause difficulty ?

if it's difficult static checker verify things when loops present, can imagine quite annoying have lot of warnings time.

i don't option of putting in assumes tell think going on, because it's invalid assumptions cause of bugs in first place !

so, when static checker can't prove something, how can go helping ? example, rewrite function recursive function - checker able verify more ? (and advocates of functional programming might how should written in first place - no changing state etc !). other ways can change code make easier static checker ?

thanks !:)

the static checker never able prove this, run-time checker will.

the static checker applied @ compile-time. in order able prove ensures, have able analyze algorithm , you're doing. not powerful.

the run-time checker of course validate ensures every time function exits, , proper unit-testing, should prove validity of ensures.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -