The World’s Leading Microsoft .NET Magazine
   
 
The .NET Addict's Blog

My Top Tags

                                                           

My RSS Feeds








I heart FeedBurner

Latest Diggs - Programming

Computers Blogs - Blog Top Sites

Site Hits

Total: 2,817,121
since: 19 Jan 2005

ASP.NET vs Ruby on Rails : Round 2 (Agility)

posted Thu 05 Oct 06

Previous score : ASP.NET 1, Ruby 1

Personally, I'm a pretty huge fan of Agile programming. For a very long time, one of my mottos has been this:

If hindsight is always 20/20, then build hindsight into your development plan. Plan to build something that you can look back on and refactor, modify, or completely throw away.

What I mean by that is when building software the "Agile" way, I often try and produce small units of testable functionality. I want to ensure ensure that not only is the code stable, but that the unit of code is meeting the demands of use cases from a business point of view (validation taking place, business rules are tested and working, etc). Once I'm satisfied with that small, discrete, fixed target of code, I can move on and go from there. That's one small aspect of Agile programming. The other aspect of making my application Agile is that it is flexible, easy to change, and easy to maintain. Having been programming for over 20 years (that's right, I'm so old that I will soon be subjecting you all to my crotchety curmudgeonry!) I know that no matter how good your design is, you are going to have to stop coding in the middle of the process and make a change. I'm not talking about refactoring for pretty or more efficient code (which you shouldn't be doing until the end of the process, if you're behaving and being a good little programmer), I'm talking about hitting Refresh on that requirements document and seeing three bullet items dissappear and two new ones appear in their place.

One of the biggest pieces of Agile programming (for me, personally) is Test-Driven Development (TDD). What this basically means is that you start out with a bunch of use case scenarios that have been properly built and agreed upon by all concerned parties (hopefully one of those parties is a good interaction designer). You then map the use case scenarios to tests. These tests can be run against your model, your view, and your controller separately or together. Some sample tests might be:

  • Create a new instance of the Product model, set its title to "Bob". Save the product in the database. Fetch that product from the database, assert that the title is still "Bob"
  • Ensure that when the controller is tasked with only displaying products  with an activity date of today's date or earlier, that each product displayed has that date
  • Ensure that when a product is rendered, the style of containing div tag is "product-item"
  • Assert that when you attempt to insert a product into the database with a price that is less than .01 (no value), an exception is thrown
  • etc

This is all really good stuff, and I'm sure you'll find that rules and test cases like this exist regardless of whether you're using ASP.NET, Java, Rails, Cold Fusion, Cobol, or anything hideous like Visual Basic (sorry, had to throw that in there... no offense to you VB folks) :) What we see here is a divergence in integrated support for this process between ASP.NET and Rails.

Here's how testing is supported by and integrated with Rails:

  • Ruby stub scripts are automatically generated for you when you use the generator script to build models, controllers, etc
  • Rails supports the notion of multiple environments for data - test, production, development being the "out of the box" environments. You can add more. This allows testing to take place in an isolated data environment.
  • Rails comes with support for fixtures. Fixtures essentially allow you to use YAML files to define what your test data looks like, either by manually entering records (that could have been serialized from a copy of live data), or by using Embedded Ruby to dynamically generate records (often used for performance tests)***
  • Rails supports the notion of  supplying separate tests for models, views, controllers, and even for performance.
  • Rails creates detailed logs of statistics of tests performed.
  • Within test scripts, you have direct access to attributes of the models, views, and controllers being tested
  • Rails has special testing methods that allow you to make assertions based on the rendered HTML output to ensure compliance with a given UI spec
  • Rails encourages Test-Driven Development by allowing you to create tests that act as a detailed spec on how your model, view, or controller should work
    • I shouldn't have to explain the benefits here. Code written using TDD has less bugs, less design misunderstandings, and needs to be refactored less than code written "traditionally". There is a plethora of reference material available on TDD, including multiple books.
*** = I can't even describe to you how ridiculously powerful this feature is. Had I known about it for some ASP.NET projects I have written in the past, I would have forced myself to write the code in Ruby, just so that I could use this feature. Either that or I would've written a bunch of complex custom code to mimic this ability.

Now let's take a look at what you can do with ASP.NET as far as TDD and integrated testing:

  • If you have a Team version of Visual Studio, you get integrated Unit Tests for business logic code and Load Tests for ASP.NET applications.
    • caveat: If you aren't using proper MVC separation, you won't be able to test pieces of your code individually. For example, using common programming practices in ASP.NET, you may find that when you create a unit test, you won't be able to tell whether the failure was in your model or your controller if you've mashed all your code into the code-behind of an .aspx page.
  • Absolutely no support for automatically wiping and reconstituting test data environments
  • ASP.NET has no concept of fixtures
  • Unit Test and Load Test results can be logged centrally to a Team Foundation Server, provided you're using a Team SKU and connected to a Team Foundation Server.
  • When testing ASP.NET code, you rarely, if ever, have any access to members of code-behind classes. For example, you cannot write an external test that examines whether or not the code-behind file has set a member variable called myCounter without writing your own complex ASP.NET testing harness system, whereas its just part of the package in Rails.
  • There is nothing to indicate that ASP.NET encourages Test Driven Development, as there is also very little within ASP.NET to encourage the true separation of model and controller. Again, its possible to do this, but it isn't as if ASP.NET sticks a big sign in your face telling you to do it now , whereas Rails forces this separation intrinsicially.
  • While ASP.NET has a configuration file that can be used to allow your code to run in multiple environments... my experience has been that you need to involve the efforts of a dedicated configuration manager to take your code from development, to build, to stage, to production. The process seems more clean and smooth in Rails with the native support for an infinite number of build and test environments.

My conclusion for this Round:

Round 2 (Agility) goes to Ruby.

Current Score: ASP.NET 1, Ruby 2.

Stay tuned for Round 3 where I compare Object-Relational Modeling and data access. 

tags:                      

links: digg this    del.icio.us    technorati    reddit




1. Craig left...
Fri 06 Oct 06 8:36 am

looks good! I am enjoying the book :)


2. Fei left...
Fri 20 Oct 06 12:50 pm

They are very good articles, Kevin. Looking forward to seeing the round 3.


3. Gil left...
Sat 21 Oct 06 9:06 pm

This is a great series! can't wait to see round 3.


4. Ryan left...
Thu 26 Oct 06 4:54 am

I've found both articles very interesting as I am starting to warm to Ruby on Rails, although currently work with ASP.Net (and eeew ASP). Looking forward to round 3.


5. Todd left...
Thu 02 Nov 06 1:53 pm

Man this stuff rocks!!!! You are the Green Lantern of ASP.Net 2.0 Vs. RoR!!


6. Peter left...
Wed 06 Dec 06 11:10 am

I have developed mostly in ASP and ASP.Net, but also wrote an app in RoR recently. I think your comparisons so far are spot on. One thing I miss when developing in RoR are the rich server controls - datagrids, calendar controls, etc. There is also a huge third-party market for rich server controls making complex GUIs with tree-views, etc. quick in ASP.Net. I wonder if there are similar things in the works for RoR (the RoR "form-helpers" aren't there yet).


7. Christopher left...
Tue 27 Feb 07 6:24 pm

I like your perspective. I've been using ASP.NET from beta. I like rails and I am about to start a new project, so I'm researching using Rails or ASP.NET. So far I prefer Rails.


8. JH left...
Mon 05 Mar 07 7:06 am

Good stuff, I have been using ASP.net since 1.0 and I have never really liked it for web based programing. I am looking for something else and this might be the ticket!


Tag Related Posts

NYC SharePoint Developer Needed

Mon 12 May 08 12:09 P GMT-05

Scott Guthrie Updates the ASP.NET MVC Roadmap

Wed 13 Feb 08 3:49 P GMT-05
tags:    

Volta is to Ajax what Tums is to my Stomach

Wed 30 Jan 08 4:11 P GMT-05

ASP.NET 3.5 Extensions Preview Released

Mon 10 Dec 07 2:10 P GMT-05

Microsoft unveils an MVC framework for ASP.NET

Mon 08 Oct 07 12:58 P GMT-05
tags:      

My Appearance in the RIA Shootout on sys-con.tv

Tue 05 Jun 07 11:41 A GMT-05
tags:              

Will Silverlight be DOA?

Mon 16 Apr 07 8:02 P GMT-05

ASP.NET Ajax v1.0 Beta

Fri 27 Oct 06 6:17 P GMT-05
tags:      

ASP.NET vs Ruby on Rails : Round 2 (Agility)

Thu 05 Oct 06 11:02 A GMT-05
tags:                      

ASP.NET vs Ruby on Rails : Round 1

Wed 04 Oct 06 1:37 P GMT-05
tags:                

First Impressions of Windows Vista RC1

Thu 07 Sep 06 1:30 P GMT-05
tags:                      

Localizing a WPF Application

Tue 22 Aug 06 11:39 A GMT-05
tags:            

WPF Slide Show and Photo Album

Fri 18 Aug 06 6:48 P GMT-05

Is Windows Workflow Foundation Too Complex?

Fri 18 Aug 06 12:15 P GMT-05

ADO.NET Entity Framework Announced Today!

Wed 16 Aug 06 11:08 A GMT-05

Scrobbles, Diggs, Flickrs and Tags Oh My!

Tue 01 Aug 06 5:25 P GMT-05

DLinq vs the ADO.NET Entity Framework

Fri 23 Jun 06 4:01 P GMT-05

The Adventures of LINQ (Not Zelda)

Fri 19 May 06 11:21 P GMT-05
tags: