.NET MVC vs Ruby on Rails

March 21, 2009

ontheroadtonowhere

Or rather, .NET MVC for Ruby on Rails developers.

Note: Some edits have been made in light of useful comments

It seems oddly regressive to be going from the polished world of Ruby and Rails to the rough hewn newborn lump of .NET MVC, but well, needs must. I’ve just finished a project in .NET MVC (RC1) and have the following thoughts that may come in handy if you are thinking of using .NET MVC instead of Rails, or are a Rails dev being forced to use .NET MVC:

  1. Learn C#. The most straightforward book I found was the Apress C# book Pro C# 2008 and the .NET 3.5 Platform. You’ll only need the first half of the book.
  2. .NET MVC is easy to grasp if you have any prior MVC web framework experience such as Rails. Do a couple of video’s of the .NET website.
  3. .NET MVC is actually .NET VC. It is an attempt to replicate the Actionpack components of Rails. There is nothing included aside from a folder labeled “Models” to help you with your persistence later and domain modeling. As others have mentioned, there are other ORM tools out there, but bear in mind these are not integrated into the framework as with Rails. There are good and bad points to this, but it does mean you’ll be writing more boilerplate code and setup for your model layer than you are used to with any of the Ruby ORMs.
  4. The community is comparatively extremely anemic, both in terms of plugins/modules and blog posts/tutorials. After the well developed ecosystem of Rails (500+ people in IRC, loads of blogs/tutorials/newsgroups, rubygems, github etc), don’t expect to be able to rely on much else other than the .NET libraries, core MVC and Contrib packages and a handful of blogs. It is still early days for the framework, but the lack of community resources will come as a culture shock.  That said, a good resource for tips is stackoverflow.com, developed using MVC .NET. From a code point of view, you will often find yourself writing model wrappers around normal .NET components, such as the Membership API, in addition to doing more setup XML pushups than you are used to.
  5. The official documentation is rudimentary. Even within the framework code, comments for methods are often non-existent. The DocRails and Rails Guides projects are good examples of how to get the community documenting the codebase and building a range of real world explanations. Unfortuanatly there is nothing like this for .NET MVC as yet, the framework is also not documented on MSDN at this stage.
  6. The API feels un-unified with different argument requirements for very similar methods. Programming to an API which is undocumented and un-unified can be quite vexing even with intellisense code completion doing the hand holding.
  7. .NET MVC is now NOT open source. Next step in joining the OSS community is accepting contributions.
  8. The routing will appear very verbose in comparison to the simple rails routing structure. That said, it does work and is round trip.
  9. C# is too verbose for most web work. This point really should not be underestimated. Edit: not really a fair point in this discussion
  10. All Ajax is done by hand (not such a problem, as it includes the jQuery library).
  11. Passing variables to the view can be extremely laborious. There is the ability to automatically pass objects of 1 type to the view using strongly typed views. Outside of that, you have to package/box up your variables into an array which gets sent to the view. In the view, you have to unpack/unbox the variables from the array and cast them to their original type before use. As you can imagine, this gets old, fast. This also leads to old .NET hands just coding everything in the view in a codebehind to “get the job done”. Edit: Another way round this from the comments is to make a custom composite object and pass this through to a strongly typed view. I’m not entirely sure how this reduces the effort required, but it is certainly true that the methodology advised in most of the Docs is to use the ViewData collection to pass variables to the view using a “package and pass” approach.
  12. It’s hard to convert ASP.NET developers to use .NET MVC as it is basically less immediately productive, and can feel like a step-backwards in their approach to webdev.
  13. As the MVC project is very much a reactionary response to staunch the outflow of devs to other MVC frameworks, there is a worry that MS will drop the project if forced to make a cost cutting decision (see licensing comment 6). They are certainly not going to drop normal ASP.NET. If MVC .NET is properly open sourced, this is less of an issue.

The list really does go on, but I guess this will do as a brain dump on my main impressions so far. After this brief first pass, I would say the features of .NET MVC 1.0 are similar to rails in the 0.7 days (’04/’05) without the ORM.

{ 9 trackbacks }

ASP.NET MVC Archived Blog Posts, Page 1
March 22, 2009 at 5:52 am
Double Shot #414 « A Fresh Cup
March 23, 2009 at 11:05 am
Javier G. Lozano
March 23, 2009 at 3:41 pm
CodeClimber
March 23, 2009 at 9:46 pm
DotNetShoutout
March 24, 2009 at 1:13 am
K. Scott Allen
March 31, 2009 at 4:18 am
BusinessRx Reading List
March 31, 2009 at 4:26 am
ナオキにASP.NET(仮)
March 31, 2009 at 7:30 am
ASP.NET MVC Archived Buzz, Page 1
April 2, 2009 at 12:54 pm

{ 37 comments… read them below or add one }

1 John Bender March 21, 2009 at 6:07 pm

I work with .NET and use Rails in my off hours, and after watching 1 video on the asp.net site for MVC I was so disappointed with how little it offers when compared with Rails.

It was a good try though, and it beats the pants off of ASP.NET and the earth-shatteringly-crappy event driven model it uses.

2 mark March 21, 2009 at 7:14 pm

“C# is too verbose for most web work.”

But this way, all the static languages will ALWAYS lose out to ruby and python.

3 eatenbyagrue March 21, 2009 at 7:17 pm

I am also primarily Rails developer trying out MVC, however i have lots of ASP.NET experience in the past. One note on the data model, the ADO.NET entities and other data providers provide very robust data model support. the reason there is nothing specific in the MVC release is that .net already provides a lot of different options that plug right into the new architecture.

4 dude March 21, 2009 at 7:26 pm

I’m so sorry. I have the occasional nightmare where this exact situation is my daily life. Like, the startup I work for one day decides to re-write everything in Microsoft’s stack. Oh man, I don’t even want to think about it!

Good luck to you!

5 Orlando March 21, 2009 at 7:26 pm

.NET MVC, in a word, is discouraging.

So far I have shipped two different projects in .NET MVC working with a very brilliant and experienced ASP.NET developer. We both suffered from the lack of clearness and smartness this framework is exposing. I hope Microsoft will improve .NET MVC; in the meantime I will resign from my current position if I have to keep on using this technology.

6 developingchris March 21, 2009 at 8:44 pm

nice write up of the experience.
I’m currently doing an Asp.net MVC project, and feel your pain on most of your points. I don’t have the C# learning as a problem, but the strongly typed views mess. Which leads my colleagues to “git-r-done” in the view is very hard to overcome.

7 TDMackey March 21, 2009 at 9:07 pm

Using IronRuby you can leverage Ruby in your .Net MVC views, and it works quite nicely. Now that .NET MVC is 1.0 it should be moving to the MS-PL “open source” scheme. So take that for whatever it is worth. Also, I don’t think Microsoft is trying to target webforms developers with their MVC framework, but rather django and rails users who may be thrown into a job where they are required to use .net technology. Coming off MIX09, there seems to be a lot of support internally at Microsoft for the framework, and I don’t think it is anywhere near the chopping block.

8 simon March 21, 2009 at 9:42 pm

Thanks for the comments all. The C# part of the experience was relatively pain free to be honest.

@eatenbyagrue: I’ll certainly be looking at the Entity Framework in the future – for this project, we got by with Subsonic in the end.

@mark: Fair point. On reflection, that one is a bit meaningless. I suppose what I wanted to get across was the feeling that there are a lot of extra characters needed to get the same result in C# for the equivalent Ruby code. The writeup was really targeted at Ruby/Rails developers who may not have actually used C# in the past.

@TDMackey: Good to hear about the movement of the framework to the MS-PL license and the internal support.

9 fukue March 21, 2009 at 11:23 pm

I think it will all come together eventually, this is Release 1.0 after all. There are a lot of rebel spirits inside MS influenced by RoR, Django etc. and it looks like they’re allowed a lot of freedom on this. I mean they shipped with JQuery after all, even tho there’s already the MS Ajax ToolKit. Sample Kits ship with open source DI libraries such as StructureMap.

The eco-system is somewhat lethargic at the moment because most people waited for the RTM to do ’serious’ work with it. I followed its evolution from the previews to the RC’s and there were always some breaking changes… Check guys like Rob Conery, Haacked, ScottGu or SHanselman if you want to have updates, news and sample projects.

About typed views.. you might want to take a look at the PresentationModel pattern… You don’t really need an array for this. This will solve most of your demands (http://martinfowler.com/eaaDev/PresentationModel.html).

There are countless of ORM tools out there, from NHibernate to Subsonic.

Good breakdown however, congrats.

10 aurora72 March 22, 2009 at 12:01 am

So it seems, the king of the desktop world, microsoft finally starts to adopt the development models of the RoR, Zend FW, etc. by adopting the MVC pattern.

put aside the difficulties in applying the MVC in .NET, that’s a nice move as it helps unify the web development process.

c# is “very much” like php except being static.
The book “Pro C# 2008 and the .NET 3.5 Platform” is a good recommendation.

11 Liam McLennan March 22, 2009 at 12:38 am

Some of this comparison is not valid. Asp.net mvc is a UI framework, Rails is an application framework. If you want a fair comparison you could compare Rails to something like S#arp Architecture. I personally think that Active Record is the worst part of rails so I am glad that MS did not bundle something like that with MVC. On thing you did not touch on was deployment options, where .NET is still miles ahead.

12 David March 22, 2009 at 1:03 am

I highly recommend looking at ScottGu’s NerdDinner tutorial for ASP.NET MVC: http://weblogs.asp.net/scottgu/archive/2009/03/10/free-asp-net-mvc-ebook-tutorial.aspx

It is awesome from a documentation perspective.

13 SDC March 22, 2009 at 1:16 am

Nice write-up. Your experiences are pretty consistent with my exposure to developing in the MS world (crummy docs, anemic community), and as for MS jumping on the MVC train: nice going Microsoft, MVC was conceived in the 70s, like me. And I am old.

14 Peter March 22, 2009 at 3:12 am

The community is “anemic”… excuse me?! Try posting a question on Stackoverflow about MVC and let us know if you don’t have your question asked in 24h? You’ll probably have it answered in minutes. I’m sorry, but I can’t take your post seriously. It’s like somebody stepping into a new country, not having a good experience at the airport and concluding that the whole country sucks.

15 Mike Powell March 22, 2009 at 3:17 am

Your point #11 is misleading; it implied (to me, at least) that if you want to send more than one type of object to your view, it has to be stuffed into an untyped array. While that’s technically true, the intent is that if you have a set of object types you want your view to access, you wrap them up into a custom ViewModel class and pass that to the view. Your multiple model objects are then available to the view as strongly-typed properties of the ViewModel. See ScottGu’s tutorial post for more information on this. The fact that you and/or your “old .NET hand” colleagues thought it best to opt for the untyped array approach makes your comparison seem like the whining of someone who just isn’t doing it right.

As for documentation, community, plugin availability, etc., I think these are all things that are humming along pretty well so far for a framework that was just released last week!

16 Shawn March 22, 2009 at 4:23 am

One plus you didn’t mention is tooling. Microsoft is passionate about it and they know it’s important for devs. Look how far Silverlight/WPF/Blend has come. It is early for MVC tooling but you can create custom t4 templates and generate off of them for views etc. It’s definitely an personal opinion but to me Visual Studio is the top as far as IDEs go. The futures for MVC also provide a way to get strong typing/intellisense in the view.

Don’t underestimate Microsoft when it comes to .Net. The ability to write in Python/Ruby/C# against a common (fairly well written) API is big.

17 John Bender March 22, 2009 at 4:37 am

@Liam McLennan yes yes miles ahead… capistrano? ASP.NET in all its forms is brutal.

18 Hadi Hariri March 22, 2009 at 6:21 am

Hi Simone,

Just a couple of points:

Despite it being a new framework, I think there’s already a wealth of information out there between tutorials, blog posts and forums.

In terms of it only being VC, I disagree. This is not an application framework as someone else pointed out. This is a web development framework, and as such gives you entire freedom of what you use as your model. There are examples such as S#arp Architecture that follow a series of conventions and use specific tools (such as Nhibernate for the ORM). It being MVC means clear separation of concerns, not that it comes with a model out of the box.

The API has changed a bit, but it was only released last week. For over a year it’s been in previews and just this year it entered RC.

In regard to passing data to the view, you can use a presentation model and therefore obtain a strongly typed model. There’s no need to use ViewData dictionary.

Out of curiosity, where did you get the info about your last point?

19 Simone March 22, 2009 at 10:47 am

I think that RoR vs ASP.NET MVC doesn’t make any sense: RoR is something that handles everything for you, while ASP.NET MVC is just a more testable, more “separated”, more web-standard compliant alternative to ASP.NET web forms.
It’s just an UI pattern, if MS had included a conventional way to access the Model, everybody would have bitten them badly: there are so many different ORM in the .NET space. Furthermore, most enterprises might rebuild the UI of their web apps every 3-4 years, but they change their business logic less frequently, so there is the need to keep a legacy code base, and make it work with ASP.NET MVC. If it enforced a convention that would have not been possible (or much more difficult).
Just to prove this, at the moment I’m working on the rewriting of a web app, but most of the services for data retrieval are still in COM+ components built in 1997 by people that left the company. So we must stay with these.

What would have been a beneficial comparison would have been comparing the way ASP.NET MVC handles controllers, subcontrollers, how it passed data between controllers and views, with the way RoR does the same things. Complaining that ASP.NET MVC doesn’t have the same things that RoR has is useless.

FuBu MVC is going to address the database-to-view approach as RoR does, but not sure at which stage of the development they are.

Well… this comment is becoming too long… expect an open response in my blog soon :)

20 simon March 22, 2009 at 1:54 pm

@Liam McLennan: Interesting to hear your opinion on .NET MVC being a UI framework. I totally agree, in reality it is a UI framework. Also, perhaps I should’ve touched on deployment. For small apps it is as easy to get a .NET MVC app up and running as an equivalent Rails app on Apache/Passenger (Drag, drop, start server). I don’t have any experience with larger .NET MVC apps, and would be interested to hear about deployment options in comparison to a typical “oneclick-deploy” multi-server Capistrano setup.

@Mike Powell: point taken about wrapping objects up into a custom ViewModel classes – that is an approach which would negate the need to use the ViewData dictionary, however I’m not sure how this would simplify the process of passing objects to the view – trading in the casting step for creation of a custom composite class. Having been exposed to the approach where instance objects are passed transparently to the view without any sort of packaging/processing, doing this step declarativly will seem a bit like pushing rope to Rails developers. Even worse, it incentivises less rigourous approaches when time is a limiting factor.

@Hadi Hariri & Simone: Fair comments. Think of this post as another datapoint for Rails devs looking at .NET MVC

21 Haacked March 22, 2009 at 9:35 pm

Regarding MSDN Documentation, we just posted some docs here http://msdn.microsoft.com/en-us/library/dd394709.aspx

We also have great tutorials up on http://asp.net/mvc

I think you’ll see even more community growth now that we hit the RTM milestone and more people will feel free to use it on a real project. After all, it was only a few days ago (Mar 18). :)

22 Mike Powell March 23, 2009 at 2:12 am

Simon, I agree that on the surface it seems like more effort to write the custom ViewModel class, but if you’re using Visual Studio or the free Visual Web Developer, having that class and referring to it in your @page declaration means you get full Intellisense support when coding your view in the markup editor. Often this can mean a huge increase in productivity.

23 Liam McLennan March 23, 2009 at 10:48 pm

@John Bender I mispoke. I was referring to the operational choices for RoR / .NET. .NET has IIS and w3wp.exe, Rails has a bunch of weak options like apache with mongrel etc. At least that was the case 12 months ago when I was learning rails. Hopefully the situation is better now.

@simon .NET does not have a popular deployment tool like capistrano. +1 RoR!

24 Roshan Shah March 24, 2009 at 1:35 am

I was .NET developer and Project Manager in 2006/7. I moved to Drupal and now am doing Ruby on Rails.

I would never go back .NET. Just 1 word for Rails – “Awesome”

Roshan
http://www.railshouse.com
http://www.roshiley.com

25 Ronald Widha March 24, 2009 at 4:11 am

like this: \.NET MVC is actually .NET VC\

26 Thibaut Barrère March 24, 2009 at 10:38 am

Hi,

some of you may want to have a look at IronRuby MVC . It’s an extension to ASP.NET MVC to support IronRuby.

cheers,

– Thibaut

27 cowgaR March 24, 2009 at 2:55 pm

well what to say, “RoR famous last words”?

see ya in year 2010 when ASP.NET MVC matures (with “futures” bringing strongly typed html helpers with lambda syntax, improved T4 templates [which by alone brings soooo much power] and scaffolding, “ui controls” in MVC words with simple drag&drop functionality [even now you can get pretty complicated controls that don't require postback working in a few minutes, how long would it take in RoR to have a powerful chart on site?] and many many others..) and becomes more popular with .NET 4.0…

it is really funny someone is comparing simple active-record toy to a .NET bear, I just can’t stop laughing…(have you ever looked at .NET enterprisy stuff under the cover which you have fully at your disposal using ASP.NET MVC?)

as to list of O/RMs, have a look and envy…
http://igurr.com/wikis/listof/orm-tools-quot-net-quot.aspx

28 Matt March 24, 2009 at 5:00 pm

What is with the bashing? Yeesh, use the right tool for the right job, this isn’t junior high folks. If someone decides to use a tool that isn’t your favorite, I’m pretty sure you’ll still live.

@cowgaR: I doubt anyone on the ASP.NET MVC team would deny the heavy influence that the likes of RoR and Django have on the project. Be thankful for those “toys”, they inspired Microsoft to keep pushing ahead.

29 Rafael Rosa March 25, 2009 at 4:15 pm

Hi,

I started with .NET MVC (sounds better than ASP.NET MVC) back in beta 3 and followed its development until RC1, but I’m a Ruby dev at heart and trade. There’s no fair way to compare RoR with .NET MVC because the philosophies behind each are very distinct. Even though there are good projects like S#arp Architecture to fill in the blanks, the experience is not the same. I’m going to tryout MVC with IronRuby, and I believe it will be a good fit. The IronRuby project is very nice, unfortunately we’re unable to contribute more effectively.

As far as community goes, the .NET is much more reactive and anemic, but that’s the way MS wanted things to be, and the ALT.NET guys are trying to shake things up, but it’s hard to change such a heavy culture. There’s no real open source project in the official .NET world as we are used to in the Ruby world.

@Liam – besides Capistrano, which is a blessing, we now have Phusion Passenger, which makes deployment a no brainer. Mongrel is going to the grave, so to speak. Some good reading about this kind of things are DHH’s posts about Rails Myths.

Cheers

30 Norman Close April 23, 2009 at 6:24 am

I do think this is a fair comparision overall and raises some good points.

I have just started on a .NET MVC Project after doing some Rails development last year. I have already written more code than an an equivalent Rails Project and I have just got started. However this is mainly because of the lack of the Model integration.

Still I am enjoing .NET MVC much more than Web Forms so it is a good step forward for web development using the Microsoft tools.

As othes have noted I am sure there is a lot more coming as .NET MVC evolves.

If all things were equal I would like to work on Rails however that is not an option in my work environment so .NET MVC is a great improvement for any web development I do.

31 Seth May 3, 2009 at 3:28 am

I’ve always hated Web Forms. Asp.NET MVC I can deal with. Web Forms were bar far the worst implementation anyone could have come up with for the web. What bothers me most about Web Forms are the programmers I have had to work with that have minimal understanding of how forms work. When you request something that doesn’t play nice with Web Forms they are completely lost. However I could ask these same people to write it in Classic ASP and it would have been less painful for everyone. I am using ASP.NET MVC on 2 projects right now and so far I have no complaints.

32 Mark May 26, 2009 at 2:04 am

Microsoft MVC is an abortion as far as frameworks are concerned. There is absolutely no productivity to this mess. This package really belongs on the bench not in production. If you have a website more complex then nerd diner stay away from the mess of a tool …. This just goes to show you how freaking pathetic Microsoft development tools have become.

33 S October 9, 2009 at 6:07 pm

You Ruby zealots keep hurling epithets at MS, I’ll keep earning $120k+ delivering MS solutions like I have since a year out of college.

34 Bob October 27, 2009 at 8:18 pm

Mark,

Why even post something like that? It adds nothing to the discussion. For my own part I would like to amplify the comments made by Rafael Rosa on the different philosophies behind ASP.NET MVC and Ruby on Rails. The ASP.NET MVC philosophy is one of control and customization (i.e. configuration) combined with a minimalist framework that is open to dependency injection and inversion of control (IoC). IMHO, one really must grok dependency injection and IoC to really appreciate fully the power and potential of the ASP.NET MVC framework. On the other hand, Ruby on Rails mixes what are essentially separate concerns, MVC in the UI and ORM in the data access layer, together in order to facilitate convention over configuration. This difference of opinion concerning dependency injection and IoC (which implicitly requires configuration) OR convention (which implicitly requires imiting choices) instead of configuration is really at the heart of the what makes Ruby on Rails different from ASP.NET MVC. IMHO, Ruby on Rails is easier to standardize (due to the conventions thing) BUT the flexibility and freedom offered by ASP.NET MVC with IoC and dependency injection is ultimately more powerful (albeit somewhat more demanding of advanced developer understanding).

35 Josh November 15, 2009 at 12:31 pm

I am a new Rails developer who has worked with .NET for a very long time. I looked at going back to MS since MVC was out but passed. My considerations:

-Considered .NET mostly because when you get use to the warm, cozy Visual Studio cave, TextMate and the like seem… well… I’ll just say VS.NET is an EXTREMELY powerful IDE that is unmatched by Netbeans/etc., and this is a point almost always lost of people who have been off MS for a long time.
-All your points are right on.
-Like a lot of MS people, I don’t care about anemic community–I got used to so many high quality printed pages, I could get whatever I needed done. It’s nice and all, but if the docs and books exist, not so important (they DONT, as MVC is new and crappy so far).

36 Josh November 15, 2009 at 12:37 pm

A point I forgot to make in the previous comment:

-I sure wish there were an analogue to this high quality post/comments for Zend Framework, as it is an equally hacky trashy mess vs. Rails. Just because you \CAN\ do a lot of stuff with it doesn’t make it a nice system. You CAN do a lot with .NET MVC but it’s all ugly and ductaped together. It cost me an entire project that I still have to maintain on that filth.

37 Lucy20 February 6, 2010 at 10:40 pm

You should be obviously a good master like the workers at the ringtone and cool ringtones providers, to create your good article. Not every person will.

Leave a Comment

Next post: Costing a website or webapp: A guide for the non-developer