DotNet Junky on Ruby Exploration - chapter 3
November 26th, 2007 RustyHistory of Vous Ruby
I’ve investigated Ruby several times. I’ve gone through the online Ruby tutorials and installed Instant Ruby (no longer supported, replaced with Bitnami RubyStack). My first real ruby experiment was to try to create an object-based text file parser to open a text file, look for a reg ex pattern, replace it, then save the file. Sounds simple enough? I was able to get 80% of the way there with very little code. In fact, I did this in iRuby (interactive commanline where you define classes as you go). This was compelling because I can’t imagine doing this in c# without a compiler… Oh yeah, its compiled, need compiler. However, I reached an abstacle as I tried to interact with the filesystem and wasn’t satisfied with the accessibility of documentation while I Googled for solutions. I finally completed my task in c# using TestDriven.net as my execution interface. TestDriven.net, by the way, wins tool plug-in of the decade award for all the benefits its brought me.
As the World Turns (Ruby)
I quickly returned to the warm bossom of my Visual Studio IDE and the C# language. However, the Ruby on Rails 15 Minute Intro kept on haunting me, asking me whether I really needed stored procedures, parameter lengths, data readers, streams, request objects, page lifecycle, etc. It’s not that these things don’t have their place but I couldn’t help but feel as though the cutting and pasting I was doing to create data access and user controls wasn’t somehow repetative. DRY?
Rails for Microsoft Junkies
So I love C# but I wanted to experiment with rails. Monorail, y’all!
I started there. The first thing I discovered was how easy simple things were. That sounds pretty trivial but sometimes I am astounded by how much crap I have to add to get data to a page in Asp.Net without violating every principle of good software design ever captured in a UML diagram. Data in the presentation tier just makes me feel dirty, I can’t sleep at night, I can’t eat. I just won’t do it. Even DataTables eak me out. Strongly-typed datasets? Who thought it was a good idea to take something dynamic and unstructured and compile the ugly thing? Intellisense, I know. I am addicted to it, too.
Of course, monorail is a gateway drug. I used monorail with Active Record to create a simple website. When I defined my business classes and used them exclusively to bring data to the view, I was excited. Then I genereated the schema for the first time. It was a dirty chunk of code in global.asax but it generated a database that was compeltely prepped for persisting every class I’d defined with no more than simple attributes. WOW!
Of course, I am a control freak and didn’t like the 1 to 1 requirement of Active Record so I learned about NHibernate. Many months later, and a significant amount of trial and error, not to mention a significant repository infrastruture, plus tremendous development and advancement by Mr. Rick Caldwell, and we now have abandoned our previous belief that all data accessmust use stored procedures and that ORM was for lazy programmers. It rocks. I LOVE database modeling. It is downright orgasmic to design your class structure according to your domain model and then generate a database schema that perfectly matches the normalized data model that you would have coded if you were required to do that by hand. Watching the sql in Log4Net is also quite entertaining and rewarding. Being able to focus entirely on the business domain and not worry very much about data access is just efficient.
Back on the Rails
For a period of time, rails was shelved in favor of asp.net using NHibernate. Recently I spoke with Mark Jones (blog link forthcoming) and he helped reinforce my belief that there is something very exciting happening on the Ruby side of the world.
He was excited about the Monorail possibilities and inspired me to explore the framework further. I dug into the ajax helpers and compared ashx handlers with controller actions and found it truly a pleasurable way to create a website. It almost forces you into good design. MVC frameworks encourage you to separate concerns. A little good practice and inversion of control is as simple as a one line code change (load from config rather than in code).
…and back to Ruby
I have been excited about a ruby port to dotnet so there must be something in that Ruby community that fosters creativity and innovation.
I am installing the RubyStack now and will begin my now far more enlightened adventure through the language. I now understand that you don’t need to compile ruby, you execute the ruby.exe commandline runtime. It will launch whatever components you need for your app. I can’t tell you how long I’ve been confused as to how exactly to execute my ruby app without visual studio. Where is F5?
I’ll keep you posted