Tuesday, November 17, 2009

Book review: Professional Refactoring in C# & ASP.NET

Three months ago I was looking up to refactoring a legacy ASP.NET Webforms application. Although I was familiar with refactoring, I ordered "Professional Refactoring in C# & ASP.NET" by Daniejel Arsenovski to get deeper into refactoring.

The title

Although the title states "Professional", I think this book should find it's main audience in coding novices. Another problem with the title is the word ASP.NET in it. The book has one chapter covering ASP.NET, with only 35 poor-quality pages in it.

Now the title has some issues, but how was the content?

The content

Danijel identifies codesmells and shows refactoring techniques to solve them. Too bad some of these examples are spreaded over multiple pages, which makes them a tad sloppy and hard to read. Danijel stresses how important Object Oriented design is. He proves this by transforming procedural code into Object Oriented code, greatly improving the readability. This book should help developers who are new to or come from a non-OO background to apply the basic Object Oriented concepts. Next to refactoring techniques, he also touches refactoring tools, unit testing and design patterns.

I think the beginning .NET developer might be able to significally start improving his codebase by reading this book. For more experienced .NET developers most of the topics handled in the book should be part of their day-to-day skillset.


All by all I was a bit dissapointed by the book, it was an easy read, had a few interesting tricks, but I expected it would go more into depth.

Something valuable I realised though.. is that refactoring isn't something you learn by reading a book, but you learn it by obeying the constant hunger for improving your code.

If you feel confident that you dig the basic concepts of writing quality code, I would instead of buying this book, invest in a good book on Object Oriented concepts or design patterns.

Monday, November 9, 2009

My trip to Madrid in ten pictures

Last week I went to Madrid with my family-in-law to visit my girlfriend's brother and cousin.

Although our stay there was rather short (only four days), we visited some of the most impressive places in Madrid:
- Stadium Real Madrid
- The Royal Palace
- Prado Museum
- Queen Sofia Museum
- Buen Retiro Park
- Plaza Mayor
- ...

As always my girlfriend took lots of pictures, you can find my favorites below. Enjoy :)

Stadium Real Madrid

Pay attention to the stitching "Jesus in first place"

Royal Palace

Ruïnes of an Egyptian temple

Buen Retiro Park

Older lady feeding the birds. I wonder what her trick is.. Four of us tried letting them eat out of our hands, but we all failed.

Sunday, November 1, 2009

Walking through a new Web Application in Visual Studio 2010 (.NET 4.0)

Although I installed Visual Studio 2010 Beta 2 the first day it came out, today was the first day I made a new Web Application. In this post I will walk you through creating a new Web Application in Visual Studio 2010. I'll show you what's new and what's different.

Creating a new Web Application

Create new project

After clicking the New project link, you will see an improved Project Template window.

Search for the Web node in the Project Templates tree. You might notice that there are three new Project Templates: Empty ASP.NET Web Application, ASP.NET Web Application and ASP.NET MVC 2 Web Application.

In this post I'll show the ASP.NET Web Application template.

Select ASP.NET Web Application

New stuff in the this template

When you look at the Solution Explorer, you will notice that there more default folders and pages. Let me walk you through them.

Solution Explorer

New references

There are some new default references.

1: Microsoft.CSharp
The Microsoft.CSharp namespace contains classes that support compilation and code generation using the C# language.
Source: Msdn

2: System.Web.ApplicationServices
The System.Web.ApplicationServices namespace provides classes that enable you to access ASP.NET forms authentication, roles, and profiles application services as Windows Communication Foundation (WCF) services.
Source: Msdn

3: System.Web.DynamicData
The System.Web.DynamicData namespace contains classes that provide the core functionality for ASP.NET Dynamic Data. It also provides extensibility features that let you customize dynamic data behavior.
Source: Msdn

The Account folder

This folder holds a few default pages that provide default membership functionality. Yes, that's right, a membership provider is baked in this template.

The Login page

The Register page

The App_Data folder

In this folder you will find the membership database.

The scripts folder

This folder holds the jQuery(!) javascript files. Yep jQuery is now even shipping with Web Forms out of the box.


Here you will find the CSS file that's used throughout the web application.

Wonder where the Webforms team got their inspiration from ;)

The default style

The Default and About page

The Default.aspx page has been here forever, but the About.aspx page is new. And it does exactly what you think it does. You can supply some information about you or your application in this page.


The Global.asax is there by default. A nice feature that has been added are inline comments that help you understand the most common application events.

   1:  namespace MyFirstWebApplication
   2:  {
   3:      public class Global : System.Web.HttpApplication
   4:      {
   6:          void Application_Start(object sender, EventArgs e)
   7:          {
   8:              // Code that runs on application startup
  10:          }

  12:          void Application_End(object sender, EventArgs e)
  13:          {
  14:              //  Code that runs on application shutdown

  16:          }
  18:          void Application_Error(object sender, EventArgs e)
  19:          {
  20:              // Code that runs when an unhandled error occurs
  22:          }
  24:          void Session_Start(object sender, EventArgs e)
  25:          {
  26:              // Code that runs when a new session is started

  28:          }
  30:          void Session_End(object sender, EventArgs e)
  31:          {
  32:              // Code that runs when a session ends. 
  33:              // Note: The Session_End event is raised only when the sessionstate mode
  34:              // is set to InProc in the Web.config file. If session mode is set to StateServer 
  35:              // or SQLServer, the event is not raised.

  37:          }
  39:      }

  40:  }


A default master page comes with the template as well.


Although I rather will use the Empty ASP.NET Web Application, I think this template is a great effort to push best practices to the novice Web Forms developer. This template helps you getting started with the most powerful features of Webforms.

What are your thoughts on this new template? Will you use it?