Code reviewThe PetShop Application

time to read 2 min | 316 words

I gave a talk about ReSharper today, and I used the PetShop demo app as the base code. I have purposefully avoided looking at the source code of the sample until today, because I wanted to get a gueniue experience, rather than a rehearsed one. I don't think it went as well as it could have, but that is not the point of this post. The point is to talk about just the code quality of the PetShop application.

First, let us see what the PetShop application is:

The Microsoft .NET Pet Shop 2.0 illustrates basic and advanced coding concepts within an overall architectural framework

The Pet Shop example is supposed to illustrate "coding concepts", but mostly it demonstrate those that you want to avoid. I was shocked by what I was seeing there.

I am going to touch just the account class, because if has enough issues all on its own. The account class is supposed to be a domain entity, but what do you see when you open it?

image

And I really don't like to see SQL inside my code.

And then there is this:

image

And suddenly I am confused, because I see a class that is doing the work of three classes, and that is just by casual browsing.

And then we had this:

image

Somehow, public fields and violating the .NET naming conventions doesn't really strikes me as a good idea.

Code duplication, like between the Account.Insert() and Account.Update(), both have significant duplication in the form of:

image 

I thought that the whole idea of a sample app was to show of best practices, and that is... quite not so, in this case.

More posts in "Code review" series:

  1. (26 Jun 2016) The bounded queue
  2. (15 Apr 2011) Who Can Help Me
  3. (01 Apr 2011) SharpArchitecture.MultiTenant
  4. (28 Nov 2007) PetShop 3.0
  5. (28 Nov 2007) The PetShop Application