Participating in the open source community and becoming an avid code reader were two themes in my six month roadmap to becoming a better developer. I made progress in both of these areas in the last few days by downloading and exploring the source code for WatiN, an open source library that I have used recently for creating automated web tests. I still have quite a bit more exploring to do before I'll fully grok how WatiN works, but I thought I would share a few of the code reading techniques that I've been finding helpful.
My preferred starting place on any new project that has good unit test coverage is to pick some unit tests for common scenarios and then run them through the debugger. I chose the Google() test from the IETest class in the WatiN test project because I had done the equivalent in my own test code when first learning how to use the library. As a side note, this was the first time that I've used the Resharper test runner and I was duly impressed (I'll wait until the next post to share my thoughts on how it compares to other test runners).
Once I get a feel for the style and basic flow of the code through some of the common usage paths, I then find it helpful to use Resharper's Type Hierarchy window and VS's Class Diagram to explore the inheritance hierarchies.
The Type Hierarchy window window in Resharper works well when I am in the middle of examining code and want to know more about the classes being used. Several other options under Resharper's Go To menu, such as Usage, Inheritor, and Base also work well for this type of exploration.
Finally, at some point I usually want to understand the big picture and see how all of the classes relate to each other. In this scenario, the View Class Diagram in the Visual Studio Team Edition really shines. It is especially nice since you can adjust the level of detail you see and then simply jump back into code by double clicking on a class whenever you are interested in a particular member.
Here are a few setup notes to keep in mind if you decide to download and build WatiN yourself:
the solution file that comes with it appears to still be in a 1.1 format because it prompts you to upgrade the project when you open it in VS2005.
You will then get a compile error that the name 'isSTA does not exist in the current context' because the required conditional compilation symbol is not set in the solution.You will need to add 'NET20' to the Conditional Compilation Symbols field on the build tab under the project properties.
In order to get the Test project to compile, you will need to download the Rhino.Mocks dll and fix the missing reference.
Depending on which test runner you use, you may find that the majority of tests fail due to the apartmentState not being set to STA, which can be fixed with a config file change.The Apartment Thread needs to be set to STA because WatiN uses COM interop with Internet Explorer.
If you try to download and upgrade the 1.1 version, the project will have an invalid reference to Interop.SHDocVw because VS2005 has a different wrapper around IE than VS2003. In this case, you'll need to manually remove the invalid reference and add a reference to ShDocVw.dll from the System32 directory.