Ruby
Article
By Dhaivat Pandya

A Look Over the Fence: ASP.NET

By 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).

--ADVERTISEMENT--

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!

More:
Login or Create Account to Comment
Login Create Account
Recommended
Sponsors
Get the most important and interesting stories in tech. Straight to your inbox, daily.