Testability and TDD are not reasons to use the ASP.NET MVC Framework

Even though Microsoft continues to tout testability as a reason to adopt ASP.NET MVC over WebForms, it really isn’t a good reason.  It is interesting that this is the first product I’ve seen where there is a first-class tutorial explaining how to test code that is coupled to some part of the framework.  Interesting, I’m unable to find a Microsoft tutorial or MSDN Library article talking about unit testing with WebForms, WCF, ASMX, Workflow Foundation, BizTalk, WinForms, WPF, etc.  Now, I’m sure there is some material, and if there is “official” documentation regarding this, I would love to know so I can help bring visibility to it.

I am a big proponent of Test-driven development, and I even teach it in the Agile Boot Camp classes from Headspring.  If you work for me, you must do TDD.  No exceptions.  You might find it odd that I say that testability is not a reason to use ASP.NET MVC.

There is ONE reason I use ASP.NET MVC.  There is ONE reason all of my employees use ASP.NET MVC.  There is ONE reason it is now part of the standard Headspring Architecture for all client web application.  What is this one reason, you ask?

It works the way I want to work, and it doesn’t get in my way.

I realize this reason is very subjective.  I’m ok with that.  My mission is not to convince the whole world to use this framework.  In fact, Headspring is responsible for a handful of opensource projects, but it really isn’t important to us that anyone else uses them.  They are useful to us.  ASP.NET MVC is useful to us.

It works the way I want to work

  • I want work work among .Net interfaces.  When I want to extend something, I like being able to create an alternate implementation for the interface.  This is the way object-oriented programming works.  The simple fundamentals hold fast. 
  • I want to work with small classes.  In WebForms, it was very difficult to keep each WebForm small.  With ASP.NET MVC, it is easy to accomplish.  Each controller action has 3 or 4 lines of code coordinating work with other dependencies.  Route configurations are easily pulled into supporting classes and wired in as an HttpModule.  Views are easily partitioned using partials.  Cross-cutting functionality is easily segmented as ActionFilters.  Rich parameter types are available through custom model binding classes that convert Querystring and Form values into domain objects.  The framework is spread out.  Simple classes everywhere.  Rendering is firmly separated from handling user input.  Business rule validation is easily kept out of the controllers and views in lower layers of the application.  In short, I never find myself trying to find just the right place to wedge in a couple of lines of code.  There are plenty of abstractions.  Every bit of code has a place.
  • I want to distribute work among several members of a team.  It is almost impossible to have more than one person working on a single WebForm.  It is rather easy, however, to have several developers working on the same controller, each have one action.

It doesn’t get in my way

  • It doesn’t saddle me with static properties and other object oriented dead ends.  Every abstraction can be substituted when the default is unsuitable. 

Back to testability

Because ASP.NET MVC is designed well, it is testable.  It was not designed _to be testable_.  It was designed to allow corresponding code to be loosely coupled.  It was designed using solid object-oriented concepts.  Any code designed in this fashion is testable.  Testability is a side effect of good design, not the design itself.

Although I love TDD, please don’t adopt ASP.NET MVC because someone has told you that it will enable test-driven development.  You can do test-driven development without ASP.NET MVC.  Adopt ASP.NET MVC based on other factors.  Adopt it if it works the way you do.  Adopt it if it doesn’t get in your way as much as alternatives.  Adopt it if it helps you move faster.  Adopt it for reasons you value. 

If you are productive with WebForms; if you don’t have any pain with your current approach, please don’t switch.

Why agile transitions initiatives might fail

This post is largely inspired by David Anderson, whom I had the pleasure of meeting at an AgileAustin meeting several months back.  In this post, David proclaims to “just say no” to agile transition initiatives.  He spells out in great detail why he believes they are risky.  Here, I would like to explore a few reasons why such a transition might fail.  This may seem odd given that I head up an agile software consulting company, Headspring Systems, and we offer agile coaching.  The big differences I explain below:

Why agile transition initiatives might fail:

  • Success is not defined and measured
  • The executive makes a “vendor” or external “coach” responsible for the transition
  • Employees are incentivized to protect their “kingdom”
  • The company culture does not have self-improvement baked in

Success is not defined and measured

As with any project, an agile transition initiative must have success defined.  First, in my opinion, a special initiative just for the purpose of improving the delivery of software is indicative of a weak self-improvement culture.  Even so, everyone participating should understand what success looks like.  Otherwise, you don’t know when you’ve arrived.  The end date of the initiative is not the definition of success, and you must have milestones along to way to see if you are on track. 

What I have just said brings in a big problem.  How do you measure the “agileness” of your organization.  The agile manifesto provides no such metrics, so you have to define your own in the context of your business.   The organizations who already have metrics around business agility, responding to the market, etc, probably already have a culture of self-improvement, in my experience.  Even if you decide on an agile transition initiative, you have to define success, and you have to measure it.  If you don’t, I guarantee that you will be disappointed with it.

The executive makes a “vendor” or external “coach” responsible for the transition

If you have handled the first risk and have defined success and success metrics, you likely will not find a vendor who will base his payment on your metrics.  After all, the metrics likely call for less project failure rate, faster response times, etc.  You probably can’t measure these things in less than a year if you really want objective metrics and not one optimized for short-term results at the expense of the longer term.  A vendor might want:

  • # of people trained
  • % of teams using an “agile” project management tool
  • # of teams with an embedded “agile champion”
  • # of successful iterations

It is really easy to accomplish the above metrics and still not make any material change in the organization.  I have worked with a client that did something similar to the above.  Most of the teams starting using some new Scrummy project management web application for project tracking.  They declared that monthly status meetings were now iterations.  They declared a member of the team to be the Scrummaster (and sent that person to training).  Overall, the same organizational problems persisted.  Vendors cannot produce real change in an organization unless the organizations executive leadership alters the culture in a meaningful way.

Employees are incentivized to protect their “kingdom”

Extreme Programming talks about collective code ownership.  In short, no line of code belongs to a single programmer.  The entire team is responsible for the entire piece of software.  This collides with the notion that if everyone is responsible, then no one is responsible.  It is counterintuitive, but with a team working closely together, it does work in practice. 

To have an agile organization, this notion must be scaled to higher-level concerns.  Each person in a department needs to be able to help improve any process.  In many cultures, it is not acceptable to call out inefficiencies in a process if someone else is the “chief administrator” of that process.  It is somehow considered to be an attack on that persons kingdom.  In the Office Space culture, if a certain process went away, that employee might be at risk of being laid off.  This is a dysfunctional culture.  Good people are constantly working themselves out of a job.  Then, they go on to the next job (at the same company).  Folks who cling very tightly to the way they work at the expense of improvement will actively work against a forced initiative of improvement.

The company culture does not have self-improvement baked in

If the company does not have self-improvement infused into the heart of the culture, then an agile initiative is not just an agile initiative.  It is an initiative to change the fabric of the culture.  Did you just notice the scope creep?  Changing a company culture is very difficult, and you cannot have a project for that purpose.  It really needs to be a conscious stream of leadership from executives who are setting the example for all of the employees.

Conclusion

I agree with David Anderson.  Just say no to agile transition initiatives.  Say yes to a company culture of self-improvement.

You should NOT use ASP.NET MVC if. . .

  • You are not very comfortable with polymorphism
  • You aren’t willing to build on top of the framework
  • You rely on 3rd party vendor controls for lots of the UI
  • You are averse to using open-source libraries

The above are four quick reasons why WebForms may be a better for for some time to come if you are an ASP.NET developer wondering whether you should upgrade to ASP.NET MVC.  Please understand that I have switched all of my employees to this latest version of ASP.NET for all client projects.  I’m also writing a book, ASP.NET MVC in Action for Manning with two great co-authors, Ben Scheirman and Jimmy Bogard, both of which write about the framework on their respective blogs.

You should NOT use ASP.NET MVC if. . . You are not very comfortable with polymorphism

ASP.NET MVC makes use of interfaces, abstract classes, virtual methods and some psuedo-AOP.  If you are not well-versed with these object-oriented concepts, then the framework might not be very friendly for you.  While WebForms uses the template method to give the developer some well-defined places to put code, the MVC framework specifies an array of extension points that leverage the power of object-oriented programming to add on and extend the framework. 

You should NOT use ASP.NET MVC if. . .You aren’t willing to build on top of the framework

Version 1 of ASP.NET MVC is just a framework.  WebForms was a framework as well as lots of plugins and features.  ASP.NET MVC has very few features.  It has some basic url helpers, html helpers, and ajax helpers.  Even these are light on maintainability and are very basic.  They leverage string literals to do their job.  Without custom abstractions built on top of these, it will be difficult to develop a maintainable application that is more than a handful of pages.  This is not a failing of the ASP.NET MVC Framework.  This is just how it is, and I think it is the strength of a flexible framework.  Jimmy Bogard describes here some of the custom abstracts we have built in order to ensure our applications are maintainable.

You should NOT use ASP.NET MVC if. . . You rely on 3rd party vendor controls for lots of the UI

There are lots of 3rd party controls and extensions for WebForms in the marketplace.  There is so much out there that you can do quite a bit without a whole lot of code.  ASP.NET MVC doesn’t have lots of extensions in the marketplace.  In fact, many of the extension are in completely unsupported places.  Steve Sanderson talks about a mechanism for areasCodeCampServer has some smart input builders.  MvcContrib has lots of goodies.  These are not supported by a vender, and the major ASP.NET component vendors don’t have offerings for ASP.NET MVC, and it is unclear how venders will package and deliver commercial extensions.  I think it’s only a matter of time, but it isn’t there yet.

You should NOT use ASP.NET MVC if. . . You are averse to using open-source libraries

Many of the competing MVC-based frameworks are open-source.  Java has several MVC implementations, and the whole of Java is open-source.  MonoRail is open-source, Rails is open-source.  ASP.NET MVC is source out in the open.  The currently offered extensions for ASP.NET MVC are all open-source or public domain (posted on blogs).  If you are unable to use code or extensions from open-source libraries, then you will have to build everything yourself, and that goes back to item number two.  MvcContrib has lots of extensions for the ASP.NET MVC Framework, and CodeCampServer uses some custom extensions that haven’t made it to MvcContrib yet (but are free for the taking).  In short, extensions are out there, but there is not one, or many, commercial vendors selling them.  They are in open-source projects out there in the community.  If you are adverse to open-source and want all the good stuff to come from Microsoft or a Microsoft Gold Partner, WebForms may be a friendlier environment.

Jimmy Bogard has recently posted on some of the techniques that we, Headspring Systems, use when building web applications on top of the ASP.NET MVC Framework.  In early 2008, I led a team that put a MonoRail application into production.  Jimmy was on that team.  From that experience, we have decided that Castle Validators are a natural fit for validating data integrity of the EditModel (the type being bound by the model binder when a form is submitted to a controller action).  This is not business rule validation.  This is merely things like: “can the characters that were submitted be parsed into a date, an int, a guid”, etc.  Once we get passed data type validation, then the domain model can work on the more interesting business rules.

This is just one of the many ways that existing frameworks can be integrated with ASP.NET MVC.  ASP.NET MVC is a wide-open framework.  You can do what you want with it.  That includes getting rid of it or replacing half of it.  Or even reimplementing a portion of it, like Jeremy Miller writes about.  If you want to intercept at the IRouteHandler level and dispense with controllers and actions, you are free to do so.  There is nothing standing in your way, and there are no brick walls.  It is near frictionless web development for us.

Html generations, which includes ID generation, is one of the areas where we have put in a lot of work.  Even in WebForms, you had to specify the last bit of an ID, and the framework would munge it to make sure it was unique.  This made it difficult for javascript and css based on IDs.  Because the ASP.NET MVC Framework gives us complete control, we decided to take control of how the IDs were generated.  We created a little bit of code that generated IDs based on the properties of the ViewModel or EditModel.  Because we have code that generates these IDs based on a type (class), we can generate these IDs elsewhere, like in our JQuery script blocks and even our WatiN tests.  What does this mean?  This means that we have ZERO risk that an ID change will break some JQuery or an automated UI test.  We segregate IDs used for CSS by convention to avoid the risk of CSS bugs too. 

By default, it is easy to have duplicated strings all over the place, but the application of solid programming principle, such as “Don’t Repeat Yourself” (DRY), lead us to simple abstractions that produce more maintainable code.

The ASP.NET MVC Framework is an enabling framework.  It is not a “hold your hand” framework.  It is not a “ASP.NET 101” framework.  You have complete control over everything.  UI patterns in the web space are not so standardized that we can turn over control to frameworks that work in the “standard” way.  Data access has reached this point where we know we need Create, Read, Update, Delete, cascading persistence, lazy loading, etc.  There are many Object-Relational Mappers that support the common operations, and many developers are content giving up complete control over data access because of the similar way leading ORMs work (Hibernate/NHibernate).

ASP.NET MVC in Action goes into some of these principles.  The books spends only a few pages covering the “default” way to write an application with ASP.NET MVC.  It then moves into ways that help you write better (more maintainable) apps.  The framework is not opinionated, but it allows you to be.

Party with Palermo location confirmed for Tech Ed 2009

Over 150 people have already confirmed their RSVP for Party with Palermo: Tech Ed 2009 Edition.  This year is the 4th anniversary of Party with Palermo.  Party with Palermo started at Tech Ed 2005 with $0 budget and 35 people in Orlando, Fl.  It has grown quite a bit since then.

If you are going to be at Tech Ed 2009, plan on arriving on May 10th (Sunday), and drop in at the Westin Bonaventure at 7PM.  The specific ballroom will be announced by May 4th.  Be sure that you are subscribed to the Party with Palermo mailing list to stay informed with this and other news about Party with Palermo.

imageParty with Palermo: TechEd 2009 Edition

May 10, 2009 – Los Angeles, CA – 7:00PM – 10:00PM

The Westin Bonaventure Hotel And Suites
404 South Figueroa Street, Los Angeles, CA
Ph: (213) 624-1000
Cover charge is 1 business card.  This will get you in the door and register you for the grand prize drawings.

  • Free to attend
  • Free fingerfood
  • Free drink
  • Free swag

image

 

Sponsors: (find out how to become a sponsor)

 

ASP.NET MVC 4 in Action

ASP.NET MVC 3 in Action

ASP.NET MVC in Action is a book from Manning that covers the newly-released ASP.NET MVC Framework. It is not a beginner book.  It is an advanced book for ASP.NET professionals.  These authors share best practices, patterns, and lots of opinions on how to use the new framework.

The MEAP is available for purchase now.

ASP.NET MVC in Action talks this week (Texas, Wisconsin)

Tuesday, 14 April, 2009, AlamoCoders

TitleASP.NET MVC in Action
Abstract:  With the new version of ASP.NET, developers can easily leverage the Model-View-Controller pattern in ASP.NET applications. Pulling logic away from the UI and the views has been difficult for a long time. The Model-View-Presenter pattern helps a little bit, but the fact that the view has to delegate to the presenter makes the UI pattern difficult to work with. This session is a detailed overview of the ASP.NET MVC Framework.  It is meant for developers already building systems with ASP.NET 3.5 SP1. 
Level – 300

 

Firday, 17 April, 2009, Center for Technology Innovation, University of Wisconsin, Milwaukee

Title:  ASP.NET MVC in Action

A full day seminar presented by Jeffrey Palermo. This workshop is being coordinated by Dr. Huimin Zhao, Associate Professor in Management Information, Lubar School of Business, UW-Milwaukee

Overview

With the new version of ASP.NET developers can easily leverage the Model-View-Controller pattern in ASP.NET applications. Pulling logic away from the UI and the views has been difficult for a long time. The Model-View-Presenter pattern helps a little bit, but the fact that the view has to delegate to the presenter makes the UI pattern difficult to work with.

This workshop is the opportunity to share the experience of Headspring Systems using the ASP.NET MVC framework on real-world systems. Headspring Systems has been using ASP.NET MVC since the original prototype and has presented on the topic at local conferences as well as Microsoft TechEd. Headspring employees are responsible for a book on ASP.NET MVC, as well as MvcContrib, CodeCampServer, and several community Solution Templates. While a lot of information is packed into the workshop, the workshop will be run in the Headspring Systems “boot camp” style by which participants move quickly and deeply through the topics. In the workshop we will work together as a simulated development team and extend an existing application using the techniques learned. Participants will work together and learn from each other as well as from the presenter.

Help Support Open Source Software – Go Vote Now

Although the company I work for is a consulting company and not a product company, we have dedicated hundreds of hours to Open Source Software projects in the Microsoft .Net Framework space.  I am telling you this not to brag or get some sort of special award, but rather to set the context for this post.  We have dedicated this much effort into Open Source projects because, we see value in sharing what we do and collaborating with others who believe in developing software that promotes a frictionless development processes.

Part of what we do is to help get a handle on how we are supporting open source and to show that there are some benefits to our company by supporting these project from a business point of view.  We are currently trying to figure out ways that we can promote some of what we do by leveraging the project websites as a way of promoting our training classes and other services which we could offer. 

This brings us to the reason for this post, the Codeplex website does not support some pretty simple mark up in their wiki. I am talking about being able to make a simple banner for our project sponsor(s).  Am I asking for too much? At a time when the economy is struggling, we all need to work together to help do our little part to make the eco-system work.  The great part about the team that works on codeplex is that they are pretty transparent.  If this feature has enough votes on their tracking system, than it will get prioritized sooner.  It is pretty cool of them to be open and honest about how their process works.  The other project hosting sites have not been as easy to access as the codeplex team, so I am on a mission to get this feature prioritized. 

If you use an open source project as part of your daily work, than I ask you to do a favor for people like myself who helper run, code, and blog about open source software.

If you want to support open source projects here is your call to action.

 Go Vote Now! 

TechEd 2009 Party with Palermo RSVP site just launched!

You can RSVP for Party with Palermo, TechEd 2009 Edition now.  Make sure to RSVP because I will have a guest list this time to avoid any line due to overattendance.  If you want to ensure that you won’t have to wait in a line, please fill out the registration form. 

If you are interested in sponsoring, please email sponsorships [at] partywithpalermo.com

 

Party with Palermo: TechEd 2009 Edition

May 10, 2009 – Los Angeles, CA – 7:00PM – 10:00PM

The Westin Bonaventure Hotel And Suites
404 South Figueroa Street, Los Angeles, CA
Ph: (213) 624-1000
Cover charge is 1 business card.  This will get you in the door and register you for the grand prize drawings.

  • Free to attend
  • Free fingerfood
  • Free drink
  • Free swag