I’ve noticed there’s quite a bit of misunderstanding among .NET developers as to what Ruby or Rails are, and how those compare to what they came to know and love in .NET. I know I didn’t understand it myself for a while. The following comments, drawn from my two previous posts (Switching to Ruby from .NET and Why should a .NET developer look into Ruby or Ruby on Rails) serve to illustrate my point:
“Had a look at Ruby but no thanks, .NET remains the way for me.”
“…are there demos or samples of Ruby on Rails that can compare with the web apps that I can create with ASP.NET or Silverlight, and components like DevExpress for the ASP.NET MVC? Is there something like that in Ruby?”
While the first comment compares Ruby to .NET, which is a comparison between a language and an entire development platform, the second comment mixes html-based applications with rich client applications built on Silverlight, brings 3rd part visual controls into the equation, and wonders whether such controls are available in Ruby (a language…).
Lots of confusion there, so I hope to clarify those misconceptions in this post.
Ruby is a language. Just like C# is a language. Borrowing a quote from the Ruby language’s website:
“Ruby is a dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write.”.
So how exactly does Ruby compare to C#? You’ll find objects in Ruby, along classes, methods, inheritance, etc. You’ll also find elements of functional programming; just like C# got some of that over time through anonymous delegates and lambdas. While C# has always been a static, strongly typed language, and eventually got a couple of dynamic features, Ruby is a fully dynamic language.
You can expect more posts covering how some of these features compare between Ruby and C#. You can start by checking out the .NET to Ruby: Classes post here on RubySource.
Who does Ruby belong to?
Ruby is an open source language, and as such, it evolves based directly off the needs of its community, whereas C# belongs to Microsoft, who has the final say as to what goes into the language.
With that being said, though, besides Microsoft’s implementation of C#, there is also an open source, cross-platform one provided by Mono.
Likewise, there is an implementation of Ruby from its creator, Yukihiro Matsumoto, or “Matz”, as well as Rubinius, JRuby (a Java implementation), and IronRuby (a .NET implementation). The fact that IronRuby exists should be an extra reason for .NET developers to look into Ruby, adding it to their bag of tricks when building .NET applications.
What’s Ruby on Rails?
So what is Ruby on Rails? A language? A framework? A platform? A company that transports the bright red color precious gemstone by train? Here we go:
- Ruby on Rails (or Rails, or simply RoR) is a web application framework that follows the Model-View-Controller (MVC) architecture pattern. Therefore, it compares to the ASP.NET MVC framework;
- Just like the ASP.NET MVC framework is built on top of ASP.NET, Rails is built on top of Rack);
- Just like there are other web application frameworks built on top of ASP.NET (such as WebForms, or FubuMVC, there are other frameworks based on Rack (such as Sinatra);
- Just like ASP.NET is written in C#, Rails is written in Ruby;
- While “most” web applications built on any flavor of ASP.NET are written in C#, all applications built on any flavor of Rack are written in Ruby.
Who owns Ruby on Rails?
Rails is an open source framework, and much like Ruby, its development is driven by the community. New features are added to the framework based off real world needs faced by their users.
What kinds of application can I build with Rails?
Since people ask questions such as “can I build applications similar to Silverlight with Rails?”, I assume clarification is needed there. To just say “you can build web applications” isn’t enough anymore. Is it a web application because it’s hosted on the web? Or because it runs in the browser? Or because it is html-based? Or because it accesses data that comes from the web?
A typical Rails application has the frontend part, which is html-based. As such, it runs in the browser. The html-pages are served up by controllers in the web server. These controllers load up models populated with data, which comes from some place the web server has access to (maybe a database in the same box, maybe a web service someplace across the planet). Once the models are up, the controllers select the view template that produces the html that is to be sent down to the browser.
Another typical Rails application may have everything just mentioned in the previous paragraph, except for the html frontend. So the application provides an API (usually a RESTful one) that other applications can call over the web. For the .NET developer, this is kind of like creating ASP.NET Web Services, or WCF Services. In this case, the other applications consuming this API can be of any kind; for instance, an iPhone application, a Silverlight or WPF application, an ASP.NET application, etc.
It is not possible to create a “client-only” application with Rails, such as the ones created using WPF, Silverlight, etc. You can mix and match technologies, though. For instance, the current project I’m working on is mostly built on Rails, but it also has a part written in Silverlight, which consumes and pushes data to a RESTful API created in Rails. The Rails part of the application also consumes an API created in Java by a 3rd part vendor, and this vendor also consumes my API in order to send over some data. Another part of this project will include applications for iOS (iPad, iPhone…) and Android, and this application will also consume the API’s provided by the Rails application.
Are there reusable components?
.NET developers are used to libraries that provide all sorts of specific functionality, such as encryption, imaging, reporting, etc. Similar things are available in Ruby on Rails, and they’re often called “gems”. There are tons of them out there: lots of library that gives you a plethora of functionality that you can add to your applications (Ruby on Rails itself is a gem!)
Recently, .NET developers have also been introduced to NuGet, a library package manager, that facilitates adding external libraries to projects, bringing in also their dependencies, adjusting settings on the project, creating specific code generators, etc. Such a thing has been around in the Ruby world for a couple of years now, and it’s called RubyGems.
What about “visual” components?
.NET developers love their 3rd party visual controls! Those existed in abundance for WinForms, WebForms, WPF, and Silverlight. Far less options exist for ASP.NET MVC. I have not run into any such thing for Rails. However, as far as I’ve seen, Rails developers are quite happy with simply using CSS and jQuery in order to create awesome websites (which are things that .NET developers are using in their ASP.NET MVC applications as well).
There are always developers who want to get the “ubber 3rd part grid that can show a gazillion of rows from a database”. To tell you the truth, I used to be like that. Not anymore. If I have a situation where I need to handle a ridiculous amount of data in a grid on the client side, that means I’m doing something wrong. I talk more about that on my “You have been deleted!” post.
Is Rails cross-platform?
The short answer is yes. Here’s the long answer:
- Any machine can access a Rails application: a Mac, a PC, a smart device…
- Usually, Linux servers host these applications, even though they can be hosted in other operating systems;
- These applications can be developed on any platform, even though Mac and Linux are by far the most popular environments. I’ve done Rails development on Windows for a couple of months, and even though that worked out to an extent, certain things either didn’t work as well as they do on a Mac, or were just too slow (such as when running automated tests).
Ruby on Rails is just a web application framework, similar to the ASP.NET MVC framework, except that Rails has been around for a longer time. I hope this post helped clarifying how some of the bits and pieces of Ruby on Rails relate to the things .NET developers are used to.
I'm Claudio Lassala. I'm originally from the overcrowded city of Sao Paulo, Brazil, and I've been living in the hot and humid city of Houston, Texas, since late of 2002. I've been developing software for over 20 years, and I've received the Microsoft Most Valuable Professional (MVP) award for the last 10 years in a row (initially for Visual ForPro, and then for C#). I have written several articles and delivered several presentations (like I've mentioned, I have learned tons from helping others learn). I'm also the host for the Virtual Brown Bag. In order to help keep my sanity from writing code, I play lead guitar in a metal band (alright, some people might say that's not the best way for one to keep his sanity…).