A Look Over the Fence: ASP.NET

Dhaivat Pandya

My first programming language was C. I started trying to learn how to code on a Windows machine. I literally spent a week just trying to get my PATH sorted out so that the C compiler would be accessible.

While I was asking around on forums, someone suggested that I install Linux because it came with “gcc” (the GNU C Compiler) pre-installed and I could just start writing code.

I headed over to ubuntu.com and got the latest build, burned it to a disc, installed it and as I typed in “gcc hello.c” and saw that it compiled, I felt a sense of surprise, nothing was ever supposed to work on the first try!

After that, I largely abandoned Windows for most of my programming ventures and discovered the wonderful world of Bash, which seemed about sixty eight times better that Command Prompt.

Most of the Ruby community runs on either Linux or Mac OS X (the latter being my current platform.) We consider Windows as unusable stuff made for large enterprises that like moving slowly.

I really wanted to see if this holds true with C# and ASP.NET. In case you don’t know, C# is a programming language that runs on the Common Intermediate Langauge, and was basically produced by Microsoft (although it has been standardized and there are open source implementations such as Mono). ASP.NET is a web framework that Microsoft created using C# (it can also be used with Visual Basic).

My eyes first fell upon the Microsoft stack (i.e. C# and ASP.NET) when I skimmed through a book about C#. In my mind, C# had been a language which was almost exactly Java, a world from which I had just escaped.

C# seemed to offer all kinds of exciting features like delegates, anonymous functions, closures, etc. Although it had similar syntax to Java, the underlying ideas were often times quite different and much more “cool”.

But, laziness pervailed and I decided that ASP.NET wasn’t open source and a closed-source web framework didn’t make any sense to me.

Lo and behold, Microsoft then open sourced all of ASP.NET. I finally decided that I wanted to learn about it.

Specifically, there’s three “flavors” of ASP.NET. First of all, there’s vanilla ASP.NET. This was the first to come along and it was meant to bring desktop application developers to the web. Essentially, it adds the concept of bringing state to the web to make things like “button callbacks” (like the ones in the desktop programming world) possible on the web.

Then, there’s ASP.NET Web Pages (also known as Razor). It is essentially Microsoft’s answer to PHP. In my opinion, they’ve made some design choices that PHP would do very well to learn from, and, as a whole it is a very good platform.

Finally, there’s ASP.NET MVC. It uses MVC (just like Rails) for seperation of concerns and gives you tools to link the Ms, Vs and Cs together (again, just like Rails).

I really didn’t want to go with ASP.NET, because the idea of adding state to an inherently stateless protocol didn’t resonate with me. ASP.NET Web Pages could have been a good choice, but, I wanted to do something that was closer to Rails. I went with ASP.NET MVC.

Starting Out

Starting out with Rails was really difficult for me. There weren’t a ton of very good tutorials that weren’t outdated (I think I started just after a major release), and it took me a while to really understand why Rails offered fast development.

It might have been my preexisting experience with Rails, but I never felt this way with ASP.NET MVC. There are good tutorials on the official website, as well as nice videos that explain concepts very well.

I quickly got up to speed with what was going on, so I feel like the documentation was done very well.

The Environment

Visual Studio (the development environment produced by Microsoft for C# developers) can be incredibly annoying, but at the same time, incredibly helpful and quick.

I usually write all my code in Vim. I really like the navigation system and I’m fairly quick with it. Moving to Visual Studio was a pain. It was back to this primitive methodology of using just the arrow keys to get to places (or, the mouse).

But, Visual Studio also offers some pretty awesome benefits. First of all, the integrated debugger is awesome. I’m not sure if something exists that is similar for Rails, but, Microsoft has done a pretty neat job on that aspect of the stack. Just using “print” statements in Ruby seems a little antiquated now.

Visual Studio also provides good autocompletion along with nice utilities for refactoring (many have told me that ReSharper makes this a lot better, but I haven’t been able to try it).

The interface, however, has a lot of idiosyncracies (I was using Windows 7, not 8, so, this may have changed in the new version although it doesn’t seem like it has). There’s just too many menus available and the most typically used items are buried too far under. I understand that Visual Studio is a large piece of code, but, in my opinion, the menus and the general interface can be simplified to the point where you can actually remember where that one menu option is.

Secondly, I dislike the idea of having to pay for Microsoft Server, but, Microsoft Azure really makes this much easier for smaller developers (it is very competitive with Amazon EC2 and Heroku).

C#

This is where the comparision gets interesting.

C# is statically typed, Ruby is dynamically typed.

C# is run by a corporation, Ruby is developed by a group of independent people.

C# is compiled, Ruby is interpreted.

However, once we look past these initially tags, C# and Ruby have many similarities.

First of all, C# is not just statically typed. They also have provisions for dynamic typing, because, in many cases, the compiler is able to infer the type (a bit like Haskell, but, not quite at the same level). This does not mean that you can stroll into C# land expecting the feel of Ruby, because you won’t get it.

It is still a much less lax langauge than Ruby, and productivity does go down a bit. However, I found that having the static typing actually helped me weed out bugs very quickly because the code simply would not compile.

I did miss the swift feel of Ruby without the need of typecasting, which I wasn’t able to get with C#. The syntax of C# didn’t feel as concise as Ruby and on the whole, and was a bit wonky at times.

However, C# does have some ideas that seem ahead of Ruby. LINQ is absolutely incredible. In short, LINQ (Language-Integrated Query) makes data queries first-class objects in C#. Initially, this seems like a waste of space, but the more I learn about it, the more exciting the possibilities seem.

Overall, I liked C# for many of its qualities, but, I felt that it wasn’t at the same level of “fun” as Ruby. However, I think the ASP.NET MVC’s features make up for this.

ASP.NET MVC

ASP.NET MVC was absolutely awesome. First of all, this is where Visual Studio really came to life. It is extremely well-integrated with ASP.NET MVC and really helps you along the way. I really haven’t found something with Rails that does the same thing (however, I’m not sure if I’d switch even if something like that existed; Vim works very well for Rails).

Entity Framework, Microsoft’s data access layer, is fun to use. I like how databases are defined using the EF Designer (I’m not sure that that is something that will be universally liked, however), and the whole process seemed fairly quick and intuitive.

The Views left me missing nothing from Rails – they seemed to be extremely similar to the Rails ERB (some of you HAML folks might be disappointed though).

All of us Rubyists like the convenience that Bundler brings, and for a long time, nothing like this “offically” existed for the Microsoft Stack. However, this has been remedied. NuGet is an awesome tool which lets you quickly add dependencies to your projects.

One annoyance is that the whole controller architecture seemed a bit off the rocker to me – coming from Rails, it seemed too complicated. The whole framework seems to suffer from the “very long variable names” disease that Java has internalized.

Aside from that, I thought ASP.NET MVC really falsifies the prejudice we have against it by being quick and productive.

Conclusion

Hopefully you enjoyed my look at ASP.NET MVC from the standing of a Rails developer.

However, I’m still learning so you might find some discrepencies. If you do, please let me know in the comments section!

Free book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

  • Alexander

    As someone who is going the opposite direction, from ASP.NET MVC to Rails, I enjoyed this article coming from the other perspective. Yes, Visual Studio is a beast, but combined with ReSharper, I almost never touch all those menus and can do 99% of my work with just keystrokes. And, I agree, the one thing I miss the most is LINQ. As far as the EF Designer goes, most MVC people don’t use it and go for the ‘code-first’ approach instead, which now includes migrations similar to Rails. And, as far as views go, you said the HAML guys would be disappointed, but you can actually swap out the view engine, if you want. There is NHaml, a port of Haml, that you can use, too.

    That being said, the transition to Rails hasn’t been too rough. Many of the concepts are similar. Not having the static typing was probably the hardest hurdle to overcome, because the feedback from Visual Studio and ReSharper immediately let you know if there was an issue with the code. Also, ReSharper is amazing, and makes Visual Studio fly. I honestly don’t even know how to use Visual Studio anymore without ReSharper. That alone makes me want to try RubyMine (by the same company that makes ReSharper), as some of the ReSharper functionality is supposed to be there, too.

    But, I’m currently not using RubyMine…or Vim…for Rails, but Sublime Text 2. So far I’m happy with it, and it even has a Vim mode, although I haven’t tried it yet.

    Yes, Microsoft actually did a good job with ASP.NET MVC, and it helped spark an open source movement within the company that got most of the Web stack open sourced. The company is changing, and It will be interesting to see where it goes. But, even after just a short time, Rails does seem to be more ‘fun’ to work with.

    Some of the concepts are taking longer to beat into my head, and I miss the auto-completion that made searching through documentation a rare event. But, I guess that’s what double monitors are for…Docs + Google on one side, code on the other!

    So far, I’m enjoying the ride. Thanks for this article.

  • Iceman

    Good article, small correction, “ASP.NET Web Pages” is not called Razor. Razor is a templating language, as are ERB and Haml. Razor can also be used with ASP.NET MVC.

    I have to use ASP.NET at my work and I do like it, but I use RoR in all my hobby projects and absolutely love it. It just somehow feels more fun, Ruby is just such a great language. It also allows me of course to not use Windows and program on my beloved Ubuntu 12.04 machine. About the only thing I do miss is Visual Studio, the Intellisense (code completion) is a great feature, and also maybe the debugging, even though I find with Rails I need it less for some reason.

  • Pavel

    It’s kinda strange to see praise for ASP.NET MVC from a person who uses Ruby. It is years behind Rails in features and doesn’t have all kinds of tools for your every need.

    • Dhaivat Pandya

      This is what I thought it would be like. However, in recent times, Microsoft has actually been coming up with some pretty cool stuff that the Rails community can appreciate. Sure, there are still gaps, but, the general direction that Microsoft is taking with ASP.NET MVC is, in my opinion, great.

    • Craig

      What features do you think it is ‘years behind’ in?

  • http://ako-kaman.com Ako Kaman

    I completely agree with @Pavel. ASP.NET is years behind Rails.

    I was an ASP.NET developer for more than 5 years. But now, I am doing Ruby/Rails and PHP/Laravel and I am really happy with them.

  • Arnon

    This is a very refreshing article. Especially coming from the Ruby community, which is traditionally very much anti-Windows on principle. Tools and environments need to be evaluated on merit, not religion. I like your approach (seems like Ruby 2.0 finally starts to address some of its worst offenses on Windows – especially IO. You could go around it with JRuby for a long time, but it’s nice to see the language starting to embrace this neglected platform.

    BTW, I am not a Microsoft apologist. For me all platforms have their pluses and minuses. Also, when you have a job, not a hobby, you cannot always choose your platform.

    As for all of you out there who want a competent editor – look no further then RubyMine (or the full IntelliJ IDEA). While it’s not perfect, you’ve got a very good debugger, very good integration with testing frameworks (RSpec, Cucumber especially), very good regactoring support (not quite as good as for strongly typed languages but far better than anything you’ll find anywhere else, and all the bells and whistles you get from ReSharper (which also comes from JetBrains). If you’re totally in love with VIM or emacs, this may not be for you – but you do owe yourself to try it. You may be surprised at the productivity advantages.

    One comment regarding long names – those are a challenge for people who use an editor with no auto-completion support (e.g. Intellisense or whatever you want to call it). If your editor forces you to type too much then *it’s a problem with the editor*. It’s really important to make code really readable and clear. Use the shortest name that achieves that, but don’t use shorter names just because your editor is simply not good enough…

  • Petar

    I liked your article and agree on most points. tnx

  • http://professionalaspnet.com Chris Love

    Hey, great post. I was chuckling at times reading through your interpretation of things. I have being doing .NET since BETA 1 so I am just used to the world. I have NOT done Ruby, but find I am mostly an Ajax programmer now and live in the Web API/JavaScript space mostly.

    So the 2 real flavors of ASP.NET are WebForms, which is what I consider classic and MVC. There are various MVC view engines and this is where it gets fuzzy for me, but I consider Razor to be one of them.

    As for Visual Studio it is rather large and extensible, as is WebMatrix. But like the other commenter I know most of the keystrokes I need and rarely use the menus or toolbars. But for someone beginning you need those things to help you out. Just like all the folks that never learned the Windows + keystrokes in Windows are complaining now that Win 8 features them LOL.

    I suggest you take a look @ WebMatrix as an IDE, it is free and much simpler than VS. I use it for my own things. I consider it to be similar to Sublime which I use from time to time. http://www.microsoft.com/web/webmatrix/

    Another thing how can you say there are not a lot of samples and tutorials? There are hundreds of thousands available online and a very rich community environment. I don’t know where you live but there is most likely a user group in your area and thusly probably at least 1 code camp a year near you. Check Ineta.org for one near you. I personally speak about 20-30 times a year at various user group functions. For example CodeMash is a big one (4 days) happening this week in Ohio.

    also check out CodePlex.com and of course GitHub there are tons and tons of open source projects there.

    Again thanks for the post, This is a good refreshing look at the stack I have built my career on the past 12+ years. And you are right the ASP.NET team has done a lot of great things over the past 5-6 years.

  • http://davesquared.net David

    Try the VsVim plugin for Visual Studio. :)

  • Pavel

    Hmm, strange choice, I’ve done completely opposite, after more then 6 years .Net I moved to Rails/Ruby and never ever wanted back to Microsoft technologies

  • http://typecastexception.com John Atten

    Nice article!

    I have spent the last few years learning to code (mostly on the MS stack) and have recently jumped into the Linux/Ruby world (like, JUST getting started). It’s exciting and fresh.

    A couple points to consider: Java and .net tend towards long, descriptive variable names because both those platforms have long had strong intellisense (MS’s word) and code-completion. You type the whole name once, and from then on, the IDE helps after you type the first few characters. Makes it easier to write fluent code, and allows a lot of code to self-explain.

    Static typing most definitely helps to minimize problems from the outset, but also imposes a formalism that probably seems foreign to a proficient Rubyist.

    I have been enjoying my exploration of what Linux has to offer. there is definitely a different philosophy at work there, and it is attractive. I enjoy both worlds, and both have a lot to offer.

    Thanks for the nice article . . .

  • Tsega

    I want to say that with regards to feature wise comparison RubyMine is very close to, if not at the same level as Visual Studio. I say this because I come from a C# ASP.NET background (but I am now using Rails more). RubyMine is also a product of the people who made ReSharper for Visual Studio, so it has some fantastic features when it comes to code completion, integrated debugger, file navigation, gem management, diagramming and a whole lot more.

    That said, a very basic but also very important difference for me when it comes to comparing ASP.NET MVC and Ruby on Rails, is the convention over configuration approach taken by Rails. It make a lot of thing easier and intuitive; for me this is something lacking from ASP.NET MVC. This is a reflection of the fundamental underlying difference you mentioned above, C# (ASP.NET) is run by a corporation, Ruby (Rails) is developed by a group of independent peoples. The question is “Which side are you on?”

  • picrap

    Two precisions:
    – C# is not run by a corporation. An open source version also exists with Mono (and works just fine).
    – C# is not only statically typed since version 4 of the language, which supports dynamic types (using the “dynamic” keyword).

    • http://muddypa.ws nportelli

      No c# is still statically typed, the dynamic keyword is just a lot of compiler trickery.

      There are other IDE options from Visual Studio too. You can even use VIM if you want. It’s all compiled by command line anyway.

      • matt

        The dynamic features in c# 4 are built on top of the dlr, as is Ironphthon etc.
        en.m.wikipedia.org/wiki/Dynamic_Language_Runtime

      • Qaiser Iftikhar

        “dynamic” is not an IDE trickery, It is really dynamic. What you are mixing it up with is the keyword “var” which is IDE magic and gets converted to static type based on the expression on right hand side.

  • http://www.philliphaydon.com Phillip Haydon

    What am awesome write up, I wasn’t expecting much when I came here, but I’m really surprised.

    If you’re still keen on playing around with .net, I suggest you take a look at http://www.nancyfx.org, it’s a lightweight framework inspired by Sinatra. I prefer it over ASP.NET MVC.

  • Paula Hunter

    Some great ASP.Net open source projects can be found here: http://www.outercurve.org/Galleries/ASPNETOpenSourceGallery

  • Dave

    There are lots of good points in the comments. I am mostly a .NET MVC developer and a PHP developer. I worked with RoR years ago and am finally getting back to it. Both RoR and .NET MVC have features that are comparable to each other and features that are better/worse than each other.

    There are lots of projects out there that are trying to bring the good parts of RoR over to .NET MVC (Oak is one).

    If you do want to continue working in .NET, I agree with Phillip Haydon, Nancy FX is incredible. It’s more of a Sinatra feel but it’s a framework that gets out of the way for the most part.