Thursday, November 25, 2010

Pex4Fun

Check out this really cool web site. Not only you can write code in your browser you also have IntelliSense. The way it works is you are given a puzzle or a duel to solve (think code breaker C# edition). The goal of the game is to write the same algorithm than the hidden solution. You get hints by running Pex against both the hidden puzzle and your solution.

Pex is a tool that will try to call a function with any kind of input parameters required to use all the code path of the function. It will highlight thing like passing null might cause a NullReferenceException down the line and you should guard against it. So by trying all those combinations against your code and the hidden puzzle will give hints on the difference of implementation. You can then update your code and try again each time getting closer and closer to the solution.

You can even create an account and keep track of all the challenges you solved. A section of the site is structured as a course where you learn about C# and cool features like Code Contracts.

Code Contracts helps us create a more declarative way of expressing pre and post conditions to our code. And because of the declarative way they works, tools can then to provides us with static compile time validation, run time guard code and automated API documentation of the contracts.

Pex4Fun is really a great way to play around those 2 great tools without having to setup libraries on our machine. I can even show some basic C# stuff to my friends, on the web and even from my smart phone (but then it’s not that fun I must admit!)

No comments: