Dec 25

Over the last few months I made an interesting transition, I switched from pure C# / .Net development using Windows to Ruby / Ruby on Rails using Linux.

Before I begin I have to say something about the context in which I used RoR. A new customer came to us and wanted a web based app for internal usage, it would be used by about 10 people. It should be accessible via Internet as the employees of said customer would work from home. I had a direct contact to the customer and deployed 3 to 4 times a week. Therefore, using RoR, even with next to no prior experience, wasn’t really a risk as the customer could always see my progress and had a more and more usable application from day 1.

The first problem was the IDE, I really love Visual Studio, at least with ReSharper and I think it was a logical choice to use JetBrains Rubymine. I don’t regret it, instead I’d advice every .Net developer that wants to try RoR to use Rubymine.

The second problem was the OS switch from Windows to Linux, I used Ubuntu 9.04 and later 9.10. I started with a VM and later switched to dual boot, please don’t make my mistake: NEVER install Linux before Windows. Windows 7 kills Ubuntus boot loader and as someone with next to no Linux experience it’s some trouble.

Linux is a pretty nice OS though, the GUIs (Gnome, KDE etc.) are pretty bad compared to Windows, so don’t expect too much, they are usable but don’t stand a chance against Windows 7. As I was used to do everything with a nice blinky blinky GUI, I tried to avoid the console, a terrible mistake. Linux’ console interface is powerful, easy to learn and (in general) way faster than doing it with the GUI. Before anyone asks, I don’t want to code without a full fledged IDE, so VI, VIM Nano etc. weren’t an option.

Back to topic or better let’s start with the topic :)

First, it’s important to realize that Ruby and Ruby on Rails are two distinct things, Ruby is a language and Ruby on Rails is framework written in Ruby. I didn’t read a book to learn either, instead I just started hacking away. Whenever I found a problem I asked mr. Google.

What I learned in the very beginning, if you don’t find a solution on google’s first page, you are trying to do it wrong. Rails is an opinionated framework, if you try to do something in a different way you are pretty much lost, but this is not a downside, it’s actually very good as you can say that there *is* THE way.

Asp.Net MVC is the complete opposite, you have plenty of choices like what data access to use etc. You won’t find a single solution for any given problem, instead you’ll get people that tell you NHibernate is the best, others say that pure Ado.Net is the best etc. But this too is not a downside, it’s just the opposite approach. RoRs pros in this area are ASPs contras and vice versa.

Rails is completely model driven and the model is database driven, Active Record is a core part of RoR. For guys that are new to the MVC pattern or have a pretty good understanding of how it should work but haven’t actually used it, Rails is really great as you’ll learn what MVC really means. ASP.Net, again, gives you the choice to do MVC or crappy VC with all stuff inside the controller.

The Rails ecosystem is really great, for almost any infrastructure concern there is a plugin waiting to be used. Be it background tasks, authentication you name it. Asp.Net has the .Net framework that might lack some comfort but is way more powerful.

I like and love C# but Ruby is so much more expressive and easier to learn or write. Even subtle things like writing do_stuff if condition_is_met?  instead of if (condition_is_met){ do_stuff(); } make a difference in terms of expressiveness.

The really disturbing thing are the background tasks. For active record and the configurations to work properly, it’s required to load the entire rails stack every time you want to execute a task. If those tasks are done every hour, it’s not a problem but if you want to do it every minute, it’s a significant overhead. It takes about 10 seconds for the rails stack to load, that’s 10 seconds of 100% CPU usage every minute for about 3 to 5 seconds of work. To get rid of this, I had to take a pretty hacky way, instead of running such a background task, I simply issue a web request to a specific url.

One thing you’ll notice is that Active Record is both, RoRs strength and weakness. For all but the simplest queries the performance is not acceptable once your db reaches a specific size and you have to fall back to raw sql. And if I may give you an advice, if possible use a copy of the production database for performance optimizing, nothing is more accurate and useful. Please note that I really love optimizing queries and that I have a pretty low tolerance before I start to work on a query (again).

Deployment with RoR used to be pretty hard, but that’s no longer the case. Just google Phusion Passenger and Capistrano. A single command (cap deploy) is enough and you’re done. It’ll take care of almost anything out of the box and is easily extendable.

Early next year, I’m going to work on a personal project with ASP.Net MVC (and Visual Studio <3) as I’d like to see how it feels after working with RoR.

Tagged with:
Nov 23

If you can live without the edge Ruby / Rails stuff, I’d recommend you to use Enterprise Ruby. Less memory consumption. Easy to install. Stable.

To install it, just get the newest tarball (at the time of writing this, its this). Unpack it and run the installer. The installer will check if you have all the required libraries, if you don’t, just install them, it shoudln’t be more than three.

Usually, the defaults are just fine, if you leave them, it will install ruby in /opt/ruby-enterprise-xxx. When your done, you should symlink the following:

sudo cd /opt/ruby-enterprise-1.8.7-2009.10/bin
sudo ln ./ruby /usr/local/bin/ruby
sudo ln ./rails /usr/local/bin/rails
sudo ln ./rake /usr/local/bin/rake
sudo ln ./gem /usr/local/bin/gem

If you want passenger, you could run the passenger nginx/apache installer, a really nice way to deploy rails apps.

You’re done. Just one thing to remember, if you install gems that create an executeable like capistrano, javan-whenever, cucumber etc, you should symlink them as well, otherwise you’ll have to call them from /opt/ruby-enterprise-xxx/bin

One more nice thing, if you installed postgresql and libpq-dev it will automatically install the pg-gem. This works with mysql and sqlite as well.

Tagged with:
preload preload preload