I happen to be reading the current issue of Redmond Developers News and ran across the article, .NET Toolbox Picks: Part II by Leonard Lobel and Brian Schmitt. In it they mention some of the usual must have 3rd party development tools (ReSharper, Reflector, RegexDesigner.NET, etc.), and one that I've never heard of, PatternExpert. It sounded like it had some good potential, trying to add a little guidance on using software patterns, so I figured I'd download it and give it a whirl.
There is no installer, just an executable, which would be fine if the product was open source or free, but at $79, I expect an installer. First thing I noticed, no support for Visual Basic, which is unfortunate, since this is a major .Net language, and an area that needs some patterns guidance. The product itself has a tree view listing 22 major patterns, and a wizard or Powerpoint-like frame, where the pattern is explained. I like the style of the pattern documentation, and it seemed easy to understand. But, when I got to the sample code, that is where things totally fell apart.
The first (and only) code I checked was for the Singleton Pattern. The fact that there were 2 implementations of a Singleton, simple, and limited number (isn't Limited Number of instances a Multiton not a Singleton?) let me know that something was amiss here. Then I looked at the Singleton Code. Since the Code Samples where done in .Net 2.0, I expected the commonly accepted implementation (Jon Skeet has a great tutorial on this topic):
public sealed class Singleton
{
static readonly Singleton instance=new Singleton();
// Explicit static constructor to tell C# compiler
// not to mark type as beforefieldinit
static Singleton()
{
}
Singleton()
{
}
public static Singleton Instance
{
get
{
return instance;
}
}
}
But instead the PatternExpert code looks like this:
namespace SingletonApp
{
/// <summary>
/// Singleton, with added reference count and release call
/// </summary>
public class zZ00singletonZz
{
private static zZ00singletonZz oInstance = null; // Single instance
private static int iReferenceCount = 0; // Reference count
protected zZ00singletonZz()
{
}
// Create or get the singleton object
public static zZ00singletonZz getInstance()
{
if (iReferenceCount == 0) // See if the object is around yet
{
oInstance = new zZ00singletonZz();// Create the object
}
iReferenceCount++; // Increase the reference count
return oInstance; // Pass the object back
}
// Release or delete the singleton object
public static void releaseInstance(zZ00singletonZz inst)
{
// Exit if already deleted or if it is not our instance
if (iReferenceCount == 0)
return;
iReferenceCount--;// Decrement the reference count
if (iReferenceCount == 0) // See if this is the last user
{
// No one needs this object, garbage collection will delete it
}
}
}
}
That code is so bad, it is scary that it is in a tool designed to teach developers about how to write good code. IMHO, it looks like something a C++ programmer that hasn't bothered to learn how to write managed code would come up with. Reference Counters? In Managed Code?
But, the tool did get me thinking that something like this (but done right), installed in the IDE would be cool. Yeah, code snippets and the Guidance Automation Toolkit cover some of this area, but they don't quite make it.