I just posted on Unit Tests and Pex. While reading through the manual and examples I came across Code Contracts. This is something available for Visual Studio 2008 and 2010 and allows developers to add some 'rules' or conditions into their code. The rules (or contracts) are designed to ensure that a piece of code follows certain rules. Pre-conditions allow us to specify that the inputs must be, for example, greater than zero or the first input has to bigger than the second. Post conditions allow us to specify things about the outputs, so for example the output of the code must be greater than zero but less than one. If Code Contracts exist in the code then (apart from other benefits) Pex will ensure that the tests it creates exercise the pre and post conditions set out in the contracts. There is lots of other clever stuff that I do not understand but this is enough for me to start including contracts in my code.
Code Contracts are part of dotNET 4.0 and can be downloaded for use with earlier framework versions. You can find out more about Code Contracts here: http://research.microsoft.com/en-us/projects/contracts/
Tuesday, August 24. 2010
Code Contracts
Unit Testing - Writing the Tests
One of the things that I should do is write tests to make sure that the bits of code I write will work under different situations, values etc. Unit Testing is the way this is done and there are several tools (including built into Visual Studio) to run tests. The real problem, for me at any rate, is writing the tests themselves. Generally I have given up and relied on my beta testers to break the code. While this generally works what is really a pain is where I introduce new bugs when the code is changed. Unit testing is a good way to avoid these errors creeping in.
I have recently discovered Pex and Moles from Microsoft Research: http://research.microsoft.com/en-us/projects/pex/
To quote the guys who wrote it:
So at last something that will generate the tests that I am too lazy or lacking in skill to write!
Does it work? Well the signs so far are very good. I have installed everything and tried it out on some of my utility methods - bits of code that do calculations for naviagation and so on. I already found some issues that I was able to fix.
It will take me a while to get my head around it all but so far I am very impressed.
I have recently discovered Pex and Moles from Microsoft Research: http://research.microsoft.com/en-us/projects/pex/
To quote the guys who wrote it:
Pex automatically generates test suites with high code coverage. Right from the Visual Studio code editor, Pex finds interesting input-output values of your methods, which you can save as a small test suite with high code coverage. Microsoft Pex is a Visual Studio add-in for testing .NET Framework applications.
Moles allows to replace any .NET method with a delegate. Moles supports unit testing by providing isolation by way of detours and stubs. The Moles framework is provided with Pex, or can be installed by itself as a Microsoft Visual Studio add-in.
So at last something that will generate the tests that I am too lazy or lacking in skill to write!
Does it work? Well the signs so far are very good. I have installed everything and tried it out on some of my utility methods - bits of code that do calculations for naviagation and so on. I already found some issues that I was able to fix.
It will take me a while to get my head around it all but so far I am very impressed.
Sunday, August 8. 2010
User Interface
The user interface is, in many ways, the most important part of a modern windows program. It is what the user looks at and what they interact with. Actually the most important code is probably the error checking code that lies behind the user interface and data entry. In a program like ADE that is probably the largest chunk of code overall!
Microsoft provide a rich collection of user interface controls linke buttons and boxes and so on. However they can sometimes be hard to use and not always do exactly what we want. They can also have limited capabilities to change their appearance. So there are a huge number of free and paid for controls developed for us.
For the last few months I have been working with Component Factory's Krypton Suite. It is certainly very powerful and provides an extended range of controls - it also lets me modify the appearance of the interface. I have gradually been moving over to these in my programs as I go along and out latest (in development) application - FS Airline Editor - uses them pretty much exclusively. Here is a screenshot of the main user interface:

It does provide for the user to change the appearance of the application to suit their own style - although we have not implemented that yet.
Microsoft provide a rich collection of user interface controls linke buttons and boxes and so on. However they can sometimes be hard to use and not always do exactly what we want. They can also have limited capabilities to change their appearance. So there are a huge number of free and paid for controls developed for us.
For the last few months I have been working with Component Factory's Krypton Suite. It is certainly very powerful and provides an extended range of controls - it also lets me modify the appearance of the interface. I have gradually been moving over to these in my programs as I go along and out latest (in development) application - FS Airline Editor - uses them pretty much exclusively. Here is a screenshot of the main user interface:

It does provide for the user to change the appearance of the application to suit their own style - although we have not implemented that yet.
Friday, April 16. 2010
ReSharper 5 Released
JetBrains have just released version 5 of ReSharper. In a previous post I blogged about ReSharper and how useful it has been in helping me to create clean code. I find it indespensible and the good news is that Version 5 supports Visual Studio 2010. So it is pretty much goodbye to VS 2008 for me (and the development of our Flight Sim utilities) and hello VS 2010. ADE is already moved over and the other applications are on their way
Tuesday, April 13. 2010
Visual Studio 2010 Released
Microsoft announced the release of Visual Studio 2010 yesterday. Today I was fortunate enough to be able to get my copy. Still early days yet but I am confident enough that I have moved the development of ADE from Visual Studio 2008 to 2010!
Thursday, April 1. 2010
Source Control - Why Bother?
I posted a while back concerning losing code and my paranoia in that respect. History Explorer helps me to revert to older code if I need to and if I mess up what I am doing. Source Control is a bit different. This is usually used by teams of programmers and allows them to work together on a single project without having people change code on something at the same time. Essentially a piece of code has to be checked out to change it and this means no one else can work on it until it is checked back in again. Another big plus is having two versions of the code. Now this affects me. I release a version of ADE (or some other program) and then start work on the next version. Bugs arrive and I am stuck with either having to modify the new code to release as a bug fix or fixing two sets of code. I have tried both and got suitably muddled up! Source control programs allow code to be branched. This means that is it possible to work on two parallel pieces of code. At some point these can then be merged back together to form a single version again. This is very useful. Source control also provides yet another back up repository for the code (never can have enough of those as long as they are suitably dated and annotated!)
There are a lot of heavy weight tools out there to do this including those based on CVS and SVN. I have tried several. Most require a good understanding of some arcane underlying commands although there are visual front ends such as Visual SVN for Visual Studio. Many need to be connected to a database server of some description either locally or on a web site somethere, There are a number of sites that provide free and paid for services.
Recently I even thought of writing my own but then I cam across Code Co-op from Reliable Software (www.relisoft.com). This does not use a central server nor rely on user to server communications. Instead it is a peer-to-peer system that uses email to transfer updates across the team. It means that each team member has a full set of code and it is therefore multiply redundant. As a team of one I don't need the cooperative stuff but I have found that it is simple to understand and integrates fine with Visual Studio. It is not cheap at $149 for the lite version and $199 for the pro. However I will be keeping it on as my source controller. It is definitely worth having and has already saved my bacon at least once!
There are a lot of heavy weight tools out there to do this including those based on CVS and SVN. I have tried several. Most require a good understanding of some arcane underlying commands although there are visual front ends such as Visual SVN for Visual Studio. Many need to be connected to a database server of some description either locally or on a web site somethere, There are a number of sites that provide free and paid for services.
Recently I even thought of writing my own but then I cam across Code Co-op from Reliable Software (www.relisoft.com). This does not use a central server nor rely on user to server communications. Instead it is a peer-to-peer system that uses email to transfer updates across the team. It means that each team member has a full set of code and it is therefore multiply redundant. As a team of one I don't need the cooperative stuff but I have found that it is simple to understand and integrates fine with Visual Studio. It is not cheap at $149 for the lite version and $199 for the pro. However I will be keeping it on as my source controller. It is definitely worth having and has already saved my bacon at least once!
Monday, March 1. 2010
Developing ADE
A while back I posted on Software Development Performance Monitors. We are currently making major internal changes to ADE in an attempt to improve overall performance. At the same we are taking the opportunity to improve the code. Writing a complex program involves lots of code and lots of opportunity to mess up! There are a number of tools available to help developers when writing code. This make it easier to write the code and also to do something called Re-factoring. This means find ways to make the code simpler, easier to use and easier to maintain. For several years now I have used a program called ReSharper from JetBrains. This is an add-in for Microsoft Visual Studio and I have become very dependent on it. It provides lots of ways to manage the development of code and re-factor it to improve performance and so on.
I am paranoid about losing my code! As a result it is backed up and saved as I go. I use a program called History Explorer by Exendo. This monitors my source code files all the time and saves changed files on the fly. Since a lot of files can be changed a lot of times this is a life saver.
Perhaps equally important to me is the need to be able to get back to a previous version. Sometimes I get carried away hacking at some piece of code and then find that it does not work. I want to go back to an earlier version. Usually I cannot remember all the changes - a function of age I suppose. So here comes version control. I use TortoiseSVN which is free and also have it save onto the internet so that the code is protected against PC failure (I hope!). This makes it easy for me to store a version at regular intervals (usually daily). It also lets me see the differences between two version which is really handy when I forget what I changed.
Well enough of development tools for now and back to Microsoft Flight Simulator
I am paranoid about losing my code! As a result it is backed up and saved as I go. I use a program called History Explorer by Exendo. This monitors my source code files all the time and saves changed files on the fly. Since a lot of files can be changed a lot of times this is a life saver.
Perhaps equally important to me is the need to be able to get back to a previous version. Sometimes I get carried away hacking at some piece of code and then find that it does not work. I want to go back to an earlier version. Usually I cannot remember all the changes - a function of age I suppose. So here comes version control. I use TortoiseSVN which is free and also have it save onto the internet so that the code is protected against PC failure (I hope!). This makes it easy for me to store a version at regular intervals (usually daily). It also lets me see the differences between two version which is really handy when I forget what I changed.
Well enough of development tools for now and back to Microsoft Flight Simulator
(Page 1 of 1, totaling 7 entries)



