Friday, May 7, 2010

Favourite Developer Tools Demo

7 May 2010

Today I demo'ed to the dev team a list of tools I have found very useful over the last few years. Here's a rundown in no particular order.

  • Code Metrics in Visual Studio
  • Xaml Formatter
  • Regionerate
  • StyleCop
  • Resharper
  • NCover
  • NUnit Gui
  • Ghost Docs
  • Reflector
  • NDepend
  • XamlPadX

Visual Studio Code Metrics Tool
Its only available in Premium and Ultimate. Its accessed from the Other Windows option in the view menu.

It gives some common / basic statistics about your code. Cyclomatic Complexity is a measure of the number of pathways through your code, this increases the number of nested conditional statements you have. It is generally accepted that this number should be less than 20 for a member. Class coupling: I read on on a wiki somewhere this should be absolutely no more than 30. This seems high to me. Suffice to say the less the easier it is to maintain and test. Inheritance should be less than 6. Check out Wikipedia  and other top google results for tolerance recommendations.

Use this analysis process to improve the usability and maintainability of your code. The simplier one method is, the easiser it is to test and consume.

Xaml Formatter
It does exactly what it says on the tin.

It puts attributes on their own line unless there is only one, and alphabetises the attributes. It will also point out "possibly" unused x:Name and x:Keys for review.
This is a very basic tool (that needs work, and I believe Craig volunteed ;-) ), so its free, see my Essential Tools page for downloading.

It sorts and arranges members within a class. This is a fantastic tool and definitely in my top 3 favourites. See the Regionerate page for more info. Its a free tool, but Rauchy would really like to eat so donate him a pizza.

From ugly to ...

Ah, Pretty.

See my Essential Tools page for downloading a customised style sheet that is compatible with StyleCop.

Keeping your code in a consistent predictable order will make it more approachable, easier for others to learn it, and maintain it. Not to mention those of us with bad memories and we forget what it does after 2 weeks, you know who you are... ;-)

This is a great tool to advise and enforce a consistent style across all your code. See here for more info the Stylecop site and the StyleCop for Resharper  site. It used to be known as FxCop and was originally designed and written by one of the senior Microsoft CLR Architects. Its totally free.
This is a must have for use along side the built in Code Analysis built into Visual Studio premium. See my Essential tools summary page for a link to a stylecop config file almost fully compliant with the  Microsoft Framework Design Guidelines (or even better still buy the book).

This is a snippet of code where you can see the warnings generated by Stylecop in the Errors/Warnings task list, and also the integration into Resharper giving the green underline indicating a Stylecop warning present on that line.

Resharper is an enormous cache of goodness that will have you screaming like a 3year old when its taken away. For more information see the JetBrains site. This is another that is easily in my top 3 favourite tools. I've been using it for more than 3 years now and I'm addicted. Believe the hype on the Jetbrains site, you easily recoup the cost of the licence inside 4 weeks in productivity savings. Here's a list of my favourite features.

Renaming: The Refactor-Rename feature will rename comments (optionally) automatically rename references in xml member documentation comments and related members. Ie: if you rename a property it will ask if you would like to rename its backing field also.

Type Navigation with Ctrl+T - easy simple and obvious.

Suggested fixes, actioned by pressing Alt+Enter+Enter. All default actions can be performed against the entire solution with the Code Clean Up Tool.

Excellent Unit Testing interface.

Superior Intelli-Sense.

Find Usages of a member or type across an entire solution.

This is but a small subset of the features in this very easy to use tool.

I have used this tool previously for better code coverage feedback and stats. Read their  web site for more detail. My exposure to it is limited; I've used it mostly through a add-in to Visual Studio called  Test Driven.Net. The amount of statistics recorded is superior to what you get out of the box with Visual Studio, and includes a graph showing your test passes over time and code coverage stats over time. Its not a free tool, but as stated provides far superior stats than Studio does.

NUnit Gui

A nice simple interface for running tests. It pulls in source code if it finds it on your local drive and Pdb's are present. Can be scripted into the build process. Also an easier to use tool for testers to ensure all tests pass before they start their own tests. See their web site for more info.It has the ability to run tests in parallel (unlike Resharper's unit test runner). Tests can also be given time out values as attributes, Resharper's test runner also ignores these. NUnit is an open source program and has been easily the most popular unit testing framework for .Net.

Ghost Docs
This is a fantastically simple and surprisingly clever tool. Its a free tool and you can download it here. It will add xml documentation comments to members and type on key combination (Ctrl+Shift+D by default). Normally it will make a surprisingly good guess at a summary description for your method. It will even pull down comments from a base class or interface. At the very least it will insert a template allowing quick entry of documentation.

This shows the default the xml documentation for the ToString override. It has pulled this comment from the System.Dll assembly.


This is the other tool easily in my top 3 favourite tools. Its invaluable for easily finding types and members, your search can be an exact match or a partial. It also shows full xml comments for every type and member.
Probably the best feature is its ability to disassemble an assembly back into C# code. This is a great learning and debugging tool. I believe the pro edition is able to allow you to debug into a third party assembly although I have never tried. There is a free edition and a Pro edition that you can licence for a small fee considering the power, here's the web site.

This is a very extensive tool, there's far more to say about it than just 2 or 3 sentences. Here's their website.

Suffice to say that it is an analysis tool for looking at types and assemblies at a high level. I have found it to be useful for two purposes: discovering and analysing an assembly or solution written by someone else upon which I am expected to add to. Secondly, its very useful to add polish to your own framework API's. It makes it easy to find members that should not be public, unused, or are too complex. I quite often use the"egg" diagram in Cyclomatic complexity mode (as a unit of measure instead of the default Lines of Code) this immediately shows me large sections that I need to refactor into more maintainable code.

The above diagram shows the "Egg" diagram in lines of code mode. You can see an excessively large method in the top left of the diagram. Sometimes lines of code is not the best measure of size of a method. Lots of lines of code might (emphasis on might) be acceptable but certainly not too much complexity. Thats where changing the mode to Cyclomatic complexity is very useful.

When refining and polishing a reusable DLL or framework I find take a good close look at the extensive report ndepend produces. In particular the grid that highlights any statistic that is in the top 15% for that stat for the DLL. These top 15% stats are highlighted in pink. Just because they are highlighted doesn't mean they are a problem, just need to be considered. This is the only complaint I have against this otherwise awesome tool. There is no way to annotate these and possibly ignore them for the next time the analysis is done.

Finally, the last feature I want to show is the CQL language built into ndepend. It gives you SQL like query syntax across your libraries looking for certain stats. For example:

You can see the CQL statement in the top left pane and the results in the below pane and also visually highlighting the selected methods. Custom queries can be built into the analyse run process.
This tool is not free, see their website for more info.

This tool has limited use in my opinion but I have used it religiously for playing around with snippets of xaml and for extracting the xaml style code from the default Microsoft controls for control customisation. I quickly find that I would rather take my snippet of xaml I am working on and copy it into a Visual Studio test project instead. But Studio does not have support for extracting control styles like XamlpadX does. I did find some source code on the net to perform just this function however, but in this case I'm I'd rather not reinvent a good working tool.

This is a free tool, here's the link.

And thats it. Go forth and multiply.

No comments:

Post a Comment