ThoughtFactory.CreateThought() A random collection of thoughts from an easily bored developer

15Apr/082

Won’t Someone Please Think of the Graduates?

Has anyone else noticed that the example source code given on MSDN and in most books is really, really bad?

Even Fowler's seminal Patterns of Enterprise Architecture shows direct use of ADO.Net Command objects and string based SQL in the code behind file of an ASP.Net page. Check out the Page Controller Pattern on page 333 of Patterns of Enterprise Architecture for an example of what I'm talking about.

How can the industry expect to produce quality work when the information being used as guidance contains absolute worst practice? Should we have disclaimers on all sample sites stating that the code contained within is not best practice, or even something remotely approaching it? Perhaps even graphic slogans and images like those found on cigarette packets. "Writing software like this could cause mass headaches and a loss of budget related continence."

We could even go one step further. Microsoft have a Northwind database, why not a Northwind data access object and Northwind business services layer? Then the examples could stick to what they actually want to talk about (e.g. data binding) instead of having to show horrible code.

Is there really a need to explain how a table adapter works just to illustrate binding collections to a DataGrid? Wouldn't it be better to see something like:

List<Customer> customerList = NorthwindBusinessService.GetCustomerList();

in a data binding example instead of another direct call to the database using a SqlCommand object? They could have a series of MSDN articles explaining how the DLLs were built, and maybe even install them in an examples directory when the Northwind DB gets installed.

It doesn't even have to be deeply layered or highly testable. I'm not asking for something that has appropriate hook points for Unity or that I can use with NMock. Just something nice and simple that everyone recognises as being an example business layer or data layer call.

This issue is especially important given how reliant people are becoming on "the Googles" to provide exact solutions to their problems. How many of you know someone who has cut and paste from CodeProject or MSDN directly into a bound-for-production project? How many have done it yourself?

Don't laugh, it's more common place than you think. Just wait till you see a web application that consists of one form and 15 thousand lines of code in the code behind file. After staring into that particular pit of darkness you begin to realise just how dangerous these examples really are.

Comments (2) Trackbacks (0)
  1. Totally agree. One of the early Wrox press books about ASP.NET 1.1 (http://www.wrox.com/WileyCDA/WroxTitle/productCd-0764543776.html) was a much better example of building an application, and keeping the data access away from the page (and it was a web site – let alone a business application). You can even still download the code for it.

    But even when you’re not writing a book, it’s not a huge logical leap to tell your readers that you’re abstracting away the data access from the presentationn layer code samples.

    (BTW. Your theme is designed by one of the more well reknown Mod Tracking musicians – Andreas Viklund)

  2. That’s the latent Amiga user coming out in me. Trust someone who held out on using Windows till 1998 to pick a theme by a prominent member of the Tracking community without even realising it.


Leave a comment

(required)

No trackbacks yet.

Sharing Buttons by Linksku