Why ASP.NET MVC compared with Rails

May 19, 2009

At the heart of this comparison are different philosophies particularly around “Constraints are liberating”.  This quote came to my attention from David Heinemeier Hansson presentation in 2005 which is here and the first part which is equally important is “Flexibility is overrated”.  Personally I really like this approach and it is what makes Ruby on Rails great to use.  However ASP.NET MVC has gone in rather an opposite direction.

Using ASP.NET MVC you start off by having to decide which Model “provider” you are going to use.  Yes, it is flexible but it you just want to get started this can be a bit over-whelming.  As noted in the excellent NerdDinner tutorial for MVC  you can choose from LINQ to Entities, LINQ to SQL, NHibernate, LLBLGen Pro, SubSonic, WilsonORM, or just raw ADO.NET DataReaders or DataSets.  Wow, maybe “flexibility is overrated”.

Yes “Literally every part of MVC Is pluggable” which can be a good or bad thing depending on your perspective.  However ASP.NET MVC is at version 1.0 and I am certain it will evolve quickly and hopefully provide default ways handling common scenarios such as validation.

So rather than goes through long list of feature comparisons I have come up with my top three points for both ASP.NET MVC and Rails.  Off course this comes down to what you place value on but I am sure there is some commonality for those who have tried both :-

Ruby on Rails Top 3 Features

1. Consistency of approach tied to convention over configuration

This is quite hard to explain unless you have tried it.  Also it is a bit hard not to sound too “fan boy” about it but from the very first demo of Rails I saw it left a lasting positive impression.

Everything is included and it is very much a case of “don’t make me think”.  With one command you can get the Rails engine to create the database using Migrations and scaffold up you entire app (Views, Models and Controllers).  Yes, yes I know you need to modify it from there but it is really well formed start.

Particularly with Rails 2 and the inclusion of REST scaffolding it got a lot better compared with Rails 1.x.

2. Heroku provides an amazing scalable instant deployment platform

Maybe there is something similar for ASP.NET but I haven’t found it yet.  Heroku provides a vast range of options and I have only used their free Heroku Garden option.  However it works very very well and it just so easy to deploy your Rails app.

In a more general sense deployment of Rails into a Linux / MySQL platofrm is simply more cost effective.  I have not tried Phusion Passenger however I keep hearing good things about how easy it makes Rails deployment which is a big turn around from 18 months ago.

Maybe cost is not the only factor and there are some other advantages with Windows hosting.  Certainly Microsoft SQL Server is a good database however in many instances is more than is needed for a Website.

3. Lots of helpful people and great plug-ins available

I didn’t want to use the word community but what it boils down to a ton of excellent resources everywhere from books to blogs to video casts.

I have found people are happy to share their knowledge and make code / plug-ins readily available to cover all sorts of very relevant functions available.

If you want to integrate your site with other Social Networking Sites or big providers like YouTube then I think you will find something much quicker than with ASP.NET MVC.

ASP.NET MVC Top 3 Features

1. Great tooling support

Visual Studio now at version 2008 really grows on  you as a powerful environment to code in.  I have used it on and off since 2000 starting with J# and it just seems to keep getting better.

The code completion (intellisense) fits strongly with VB.NET and C# more naturally than it does with Ruby being dynamically typed.

Oliver Steele recently wrote on language mavens and tool mavens which I found interesting.  So I guess that puts me in the tool maven category with this feature.

Good integration with SQL Server and strong tooling around the database in the form of Management Studio make it quite a compelling experience.

Not to mention 3rd party and build in utilities for code analysis, refactoring.

2. Development performance

I emphasis the development side of it as once you are in Production it is quite a different scenario.

The bottom line is that Ruby runs comparatively slowly on a Windows PC and waiting for Rails to start it is a bit of a drag.  Admittedly I it was hard to tell if it was the Ruby WebServer eg Mongrel that may have been slow starting but in comparison ASP.NET is instance.

Arguably if I was serious about Rails development I would have brought a MAC or at least using Linux.

Admittedly in the scheme of things this is a minor annoyance and I certainly appreciate all of the effort that has gone into porting Ruby MRI on to Windows has outline in this interview with Luis Lavena

3. I get to do more of it and it is more productive that WebForms

Since 2003 I have done various WebForms projects with varying degrees of success.  The smaller ones were quite successful but the larger ones got quite bogged down.  My GridViews in particular was a bit of a love hate relationship trying to get them to work as I wanted.

In comparison to WebForms ASP.NET MVC has been a breath of fresh air.  Nice clean HTML with no ViewState and “real” HTML form elements without layers of abstractions eg “TextBoxes” that became “TextAreas” etc.

Client side validation controls in WebForms was an area from day one I found clunky and shifting that into code within the ASP.NET MVC Models is much “nicer”.

Having completed my first ASP.NET MVC project I am pleased with the results and the ease with which I can change it.  The initial development always being the smallest part of the work with ongoing enhancements being what is really critical.

Ruby vs C#

This is an area that I am neutral about.  I have realised that I have simply not invested the time to learn the power of Ruby and get the most from it.  

It was only when I read Chapter 2 of the book Rails for .NET Developers.  This chapter which is available for free here is called Switching to Ruby.  I realised that you can code Ruby like C# or probably any other language but you simply won’t get the benefits.  I know in hindsight this very obvious but there are some many subtleties to Ruby it is easy to miss them until it is explained clearly.

For me as a VB.NET programmer I know .NET and spent a couple of years on JAVA so C# feels comfortable.  The .NET framework is very comprehensive and well documented.  Not to say there is not good documentation on Ruby but probably not to the same consistent level across all the libraries.

In the end…

I know I am sitting on the fence.  I have learned a lot from Ruby on Rails that I can apply to ASP.NET MVC so for that I am very grateful.  Maybe I can have my cake and eat it too as a Microsoft Developer.

I know this sounds a bit cliché but “if you do something you love you will never have to work a day in your life”.  Bring it back down to reality I am looking for something that keeps up my interest in software development and does not frustrate me at each turn.  For the moment ASP.NET MVC has restored my enthusiasm for Web Development.

So for the moment my main focus in the Web Development area is on ASP.NET MVC but I will always keep across the developments in Ruby and Rails.  For me it is a matter of balancing what I know and am productive with to learning new things that are potentially more productive.

For someone else’s view I thought this post by Kevin Pang was a good summary


Trying Komodo Edit 5

December 29, 2008

Although I use Visual Studio 2008 and Ruby In Steel it is not a light weight option if you need to install it on another PC.

In terms of alternatives I have tried Notepad++ and although it seems very good I just have not taken to it.  It is hard to know exactly what it is, maybe the clutter of the menus.  It certainly has a lot of plugins and I would definitely want to use the File Explorer one if I was to use Notepad++ regularly.

Previous experiences using Intype and E Text Editor had been mixed and I don’t believe there has been any significant recent changes with either of these.

Then I read a number of positive posts about Komodo so decided to give it a try.  This is not by any means all the features but some highlights :-

  • File / Project Explorer which to me is an absolute must for Ruby on Rails given the number of files to update.  In Komodo Edit this is implemented as a Project Explorer which does have the advantage that you can “hide” files you know you won’t edit.  To “hide” a file you select delete which gives the option of removing a file from a Project which could be a bit more intuitive
  • Overall it has an uncluttered elegance.  The dialogs are clean and clear.  Similarities to Firefox are I am sure not a coincidence considering Komodo Edit is built on the Mozilla code base
  • Keyboard options seem to default to the same as those in Visual Studio.  Just one example is the very useful “find in files” which is Ctrl+Shift+F
  • Comprehensive feature set with everything I can think of included.  There is even the ability to record macros and edit them in Javascript
  • As noted on the features page it supports all the platforms which could be very handy if I decide to use Linux

As an aside apart from the clear leader of TexMate editors for Ruby on Rails development it is a very open field with Komodo at about 1% usage according to Ruby Survey Results .  Generally in the comparison of text editors there seems to be one particular feature that each particular advocate considers critical.  For example folding (code folding, html folding etc) is very important for some people’s usage but something I could personally take or leave.  However overall I feel that Komodo Edit has almost got something for everyone.


ASP.NET Building Blocks

November 30, 2008

A little bit of an aside from Ruby on Rails but at least it is related to Web Development.

It has been almost two years since I built an ASP.NET Web-site of any size.  Back then I used the patterns outlined in the Data Access Tutorials on the ASP.NET site.  This series of lessons by Scott Mitchell is very strong on using :-

  • Typed DataSets
  • .NET 2.0 Controls such as GridView
  • Separation into Business Logic Layer (BLL) and Data Access Layer (DAL)

For my implementation I used Stored Procedures for all access to SQL Server 2000.  In summary it worked well but was very cumbersome to change.  Even small changes involved a lot of “turning the handle”.

So fast forward to 2008 and there are a lot more options with .NET 3.5 and other developments.  So what to choose?  I’ll start at the bottom of the stack and move up

Database

In the environment that I work in there is an easy default choice of SQL Server 2005.  Having used SQL Server for 5 years now I am very comfortable with it and find there is a lot to like.  The Management Studio makes it easy to work with the database independent of the application which is very helpful.

Database Access / Object Relational Mapper (ORM)

This is the area where there is a lot of choice.  Having tried out Ruby on Rails the benefits of Active Record are clear so something similar would seem to be desirable.

Things are also evolving in this area so it does make the choice of where to invest you time in learning a new technology not that clear.

This post from Rob Conery aptly titled Choosing Your Data Access Method would seem to answer the question however it is almost a year old (December 2007) and things do move on.

I was considering LINQ to SQL as there are a lot of good tutorials on it that link to the MVC framework.  Also I had not caught up with where things are heading in the space with the future development of LINQ to SQL.  This is covered at here however I still feel LINQ to SQL is a “safe” choice for a light weight data access method.

So to cut a long story short I am going to try out SubSonic.  For no other reason than it comes highly recommended and other members of my team are using it.

Frameworks

Frameworks may not be the right term but I am looking to use ASP.NET MVC  but this still gives you lots of choices to make (C# vs VB, Data Access methods etc).  The Model View Controller (MVC) pattern has clear advantages and familiarity from a Rails development perspective.

JavaScript Library

From an end user perspective I really like the addition of a bit client side “magic”.  Particularly the yellow fade technique made famous by 37 Signals and partial page updates rather than page loads.  Using ProtoType in Rails is really easy and I am hoping that using jQuery will be just as easy in ASP.NET.  jQuery is an easy choice as it the most popular library and links in with Microsoft as Scott Guthrie explains here.

Other Bits – what have I missed

At this stage for the type of Web applications I develop I don’t think I need Silverlight .  JavaScript combined with AJAX provide some fairly powerful and high performance client side functionality.  JavaScript is continually evolving (TraceMonkey etc) so still has “some legs in it”.  Off course Silverlight comes into it’s own for embedding video and other media.

In Conclusion

At this point this is a theoretical exercise as I don’t have first hand experience with Subsonic, ASP.NET MVC .  However at some point you need to make a choice of technology and then move forward.  After that as they say “you can’t learn to swim without getting in the water”.


Microsoft Dynamic Languages

October 17, 2008

One of the most interesting presentations that I attended at Microsoft Tech Ed New Zealand was on Dynamic Languages by Harry Pierson . Harry’s presentation was mainly focussed around Iron Python although the same principles in the larger apply to IronRuby. As an aside I have found John Lam’s blog a good resource for keeping track of developments with IronRuby. The common linkage is the Dynamic Language Runtime (DLR) .

Have attending the presentation it caused me to think in more depth on some questions I had not really considered :-

  • Why Dynamic Languages? How much more powerful and productive are they?
  • Where Microsoft fits into the Dynamic Language “landscape” – why and where are they are at?

In the end it is the first question that is of more interest to me at the moment. There is quite a lot of alternative Ruby language implementation like Rubinus and JRuby that are progressing in parallel to IronRuby. In some ways these exist to meet certain niches but for where I am at I am happy to use the standard Ruby (MRI) and focus on my learning.

However the whole “why” of Dynamic Languages has interested me in that I could well be more productive than I currently am.

Wikipedia makes a distinction between Dynamic Languages and Dynamic Typing but I think most people associate them together i.e popular and more modern (hardly new) languages like Python, Ruby and Javascript are Dynamic – Languages and Dynamically Typed.

Ironically it is easier (for me at least) to put forward the benefits of statically typed languages however these are often over stated so here are the two big ones

Statically Typing – Advantages Counter for Dynamic Languages
Improved performance. Largely achieved by memory management optimisation i.e. just allocating the right amount of memory space to store variables (taken to extreme use of Pointers as per C) Yes, dynamic languages may be slower but focus on “hot spot” analysis i.e. for a lot of operations performance is not critical so only tune as required
Type checking reduces the number of errors. As this checking is done by the compiler this offers a boost to productivity by finding the errors before run-time This is one of those “yes but” things. There are so many other errors / bugs that could occur is it really as big benefit as it may first appear

So having got that out of the why of Dynamic Languages seems to me to boil down to a couple of things and I will add to this as I discover more :-

More concise and expressive code

Less additional lines of code that don’t add value. This is quite hard to quantify but the more I use Ruby on Rails the more I am surprised at how little extra “fluff” there is. One line of code is often all that is required for a method

Looser coupling of objects

In the talk by Harry Pierson he described this has solving the “double schema” problem. This is another thing that can be consider a good or bad thing depending on your perspective. However personally I have found that having to mirror each change to the Database schema with a change to the typing of the variables in the code is quite an overhead. There are workaround’s to this in statically typed languages but in the end Dynamic languages just make this less complicated.

So in summary…

They say “seeing is believing” so in this case the more I use Ruby the more convinced I will be about Dynamic Languages!


Web Future Trends

September 8, 2008

Last week I was fortunate enough to attend Microsoft Tech Ed 2008 New Zealand. There was a huge amount of varied content but I am focusing on two sessions I attended (expect another post on Dynamic Languages).

One of my most anticipated sessions was a panel discussion on Web futures – the next 18 months. I was expecting to hear contradictory views on where things were heading.  Maybe I should not have been surprised that there seemed to be rather a lot of consensus. It is a “give in” that there may have been a Microsoft focus but nevertheless I was expecting more sparks to fly.

Why I was so interested was to focus my learning around the technologies that are likely to become dominant.  May be more importantly to learn which new and existing businesses will thrive as the Web develops.

The more I thought about what I had heard I was reminded of a quote that goes something like

Those who know about the future are too busy creating it to talk about it

Even 18 months is a long time.  Looking at the history of YouTube it was only 18 months from launch to being purchased by Google.

As another aside Blake Ross , one of the main creators of Firefox is still only 23 years old.  So the view of any one over 30 on the future of the Web may not be that relevant (that includes me by the way).

So here is my view of what are some of the most significant technologies going forward :-

Ruby on Rails

Enough said, won’t labour it further here.  The addition of Internationalisation is another sign of it’s maturity and completeness.

Eliminating Multiple User-names

For the end user, me included this simply becomes too hard to manage.  Every retailer on the Web seems to have a different user-name and password they want you to remember.  Google Account, Microsoft Live ID were mentioned.  However let’s not forget OpenID and I am determined to learn more about how I can use it on any sites I develop.

Microsoft SilverLight

Whatever degree of success or adoption Silverlight achieves it will be significant in shaping the future of the Web.  Off course SilverLight is not a replacement for Flash however it is inevitable that comparisons will be drawn.  As Flash enters it’s 12th year and now has the strong back of Adobe it will be interesting to see what happens.

Elastic Computing Platforms (ECP)

I prefer the terms ECP to Cloud Computing as that sounds a bit fluffy.  It is very much a reality with Amazon EC2 Service . I began to appreciate the significance of Cloud Computing when I read on Akita on Rails Blog Post on the topic.  Google App Engine and off course Herkou for Rails use this technology.  I also expect given time there will be more database engines that solely exist for on-line storage similar to Google’s BigTable .

High Speed Internet

The keynote address at Tech Ed features leaders from both of New Zealand’s main political parties giving their visions for the future around providing Internet to homes and businesses.  This will and always has driven what applications are going to be used in practice.  Just one example, my monthly cap on Internet usage is 3Gb so why would I use a service such as Mozy for on-line backups.  Mozy itself may be free for up to 2Gbbut with such restrictive limits there are some countries like New Zealand where these sorts of service just are not going to be used (much).


Using Ruby In Steel

August 19, 2008

After trying various other editors for Ruby on Rails I have settled with Ruby In Steel Text Edtion.  The reason that I have gone with the Text Edition is that priced at the more affortable US $49 but still has the features I need at this point.

When it comes down to it Ruby in Steel is a plugin for Visual Studio 2008.  So it seems a bit strange to back with Visual Studio 2008 which is the tool I use nearly every day for Visual Basic.NET development.  Of course that is somewhat of an advantage in knowing the keyboard shortcuts and other features.

One thing I really like about Ruby In Steel is that is very well documented so you feel as though you are getting something of substance for the cost of the licence.

The other handy consideration for me is that while you are in Visual Studio you can do all of your HTML editing with very good CSS support.  I must admit this is an area where Microsoft has made a big investment and provided many improvements.  The split view between source HTML and visual representation provides “the best of both worlds”.

I will keep watchin the progress on Intype and E Text Editor as they are both good products that have the potential to be great in my view.  Intype particularly is making very slow progress and I have a look every couple of months to see if anything has changed (much the same as my own progress with Ruby on Rails).


Managing SQLite Database from Visual Studio

August 1, 2008

I am a great fan of SQLite because it is such a light weight and easy to develop against SQL database.  Because of it minimalistic nature you don’t get by default a lot of management tools.  However when it is integrated into Visual Studio it is easy to use.

Now that I have started using Ruby In Steel it is great to have SQLite database viewing and editing integrated into Visual Studio.

It is many thanks to the ADO.NET 2.0 Provider for SQLite that is available from System.Data.SQLite that this is possible.  After downloading SQLite-1.0.54.0-setup.exe and running the installer it elegantly let you select which versions of Visual Studio to integrate it into :-

Designer Installation

Designer Installation

So now when you go into Visual Studio and add a new Data Connection to Server Explorer you can choose SQLite as below :-

Add Data Source

Add Data Source

So finally you get to view and manage your SQLite database from within Visual Studio :-

Database Viewing

Database Viewing


Useful new Windows utility tools

July 27, 2008

Recently I received the good news that I am going to be attending Tech Ed 2008 in New Zealand . I understand that Scott Hanselman will be on of the speakers.  One of the many things that Scott is well known for are his annual list of top tools for Windows.  This inspired me to look again at the list of tools.

Also this year I started using ClipX which I found out about on Jeff Atwood’s blog here.  Anyway ClipX has been hugely productive for me.  I had tried ClipMate but it was just too much whereas ClipX gets it just right in terms of usability and being light weight.

Anyway from Scott Hanselman long list it lead me to two great finds :-

  1. SlickRun is just such a quick and simple way to open applications.  With some many things on my Start Menu it is a really time saver and well worth the time to set up.
  2. Speedfiler is an add-in for Outlook that really quickly allows you to file your emails into Folders.  Despite it’s cost (starting at US $25) and limited scope it works so well I am seriously considering purchasing it

Obviously there is a lot more on the list however it is always a balance between what is useful or unnecessary.


Git easy for easy things

July 14, 2008

One of the primary things that I am looking for in a Source Control Management (SCM) system is a way to manage the history and view various snapshots.  Of course there are lots of other features once you are colloborating with others but this is my starting point.

It is hard not to heard of Git as it is getting a lot of attention.  I also got the impression that it was hard to use particularly for Windows users.  Obviously for it’s advanced features there is extra learning required but to do the basics I have found it easy which has been a pleasant surprise.

Recently I watched the video here on YouTube that Linus Tivolds did to Google staff.  It is a good watch and one of the things he mentioned more that once it that is progressively getting a lot easier to use GIT and will continue to do so has more tools become available.

For my own reference I record the steps to get up and running with a local repositary and compared to a lot of things it was pretty damn easy :-

1. Install msysGit . I went with Version 1.5.5 and accepted all of the defaults presented by the Windows Installer.  I have installed it on Windows XP and Vista without any issues.

2. Basic configuration of Git is carried out at the Git Bash

$ git config –global user.email Your.Email@domain.com
$ git config –global user.name “Your Real Name”

3. Now comes the part of adding your Project into a Git Repositary.  This is all covered in the tutorial here but to show you how basic it is I will continue.   In Windows right click on the Folder where your Project is and click on “Git Bash Here” and then type command below to create a Repositary

$ git init

Git will reply

Initialized empty Git repository in .git/

4. Next, tell Git to take a snapshot of the contents of all files under the current directory (note the .), with git-add:

$ git add .

This snapshot is now stored in a temporary staging area which git calls the “index”. You can permanently store the contents of the index in the repository with git-commit:

$ git commit

This will prompt you for a commit message. You’ve now stored the first version of your project in git.

The trick here is that it opens the VIM editor which is set as the default.  In the top line type the description then press Esc key to stop editing.  Now press the : key to enter a command as per VI editing.  Commands are “write” to save and then “quit”. Below is a screen shot of what it looks like :-

Git Confirming Commit

Git Confirming Commit

Now you are up and running using Git you can use commands such as the ones below to view the status and any changes since the first commit

Using Git to view Repositary Status

Using Git to view Repositary Status

Off course there is a lot more to it and Git Hub seems to be the place to be when it comes to sharing Projects etc. But you have got to start somewhere. I found Kyle Corde’s blog post of Getting Started with Git and GitHub on Windows to be a good guide.


Part 2 – Progressing Website Poll in Rails

June 7, 2008

It has been slow progress so far. So I have decided to take an alternate approach and work through the Depot Application tutorial in Agile Web Development with Rails, Third Edition .

I have been able to make some progress on building the admin interface for Website Poll.  It took me quite some time to understand the associations functionality. 

The first part in associations of setting it up in the models is straight forward enough.  For example :-

class Rating < ActiveRecord::Base

  belongs_to :website

end

and

class Website < ActiveRecord::Base

  has_many :ratings

end

This sets up the associations in the Model but has not effect on the database i.e. you are not setting any constraints such as Foreign Keys on the database.

The area where I had problems was in using the associations setup. However I was “over thinking” it and in the end it was really simple. For example in the view (Index.html.erb) :-

<% for rating in @ratings %>

<tr>

    <td><%=h rating.website.url %></td>

This is the secret to it where it has “rating.website.url” and because of the associations being set it knows that “url” is associated with the website model. It almost seems too simple to work but it does.