Archive for the ‘ruby’ Category

Ruby is the R in Rails

I would love to have attended RailsConf 2008 but alas you can only do so much in a day. Although this was a Rails conference, it seems that this year there was less talk about Rails and more about Ruby. This is hardly surprising really given that Rails is just a web framework. Yep, Rails is just a web framework. And just like any other web framework, its serves as a gateway from the web and into your enterprise. Now, after a year of doing Rails, you’re basically done. Coasting. Yes, there are tips and tricks you can pick up along the way but for all intense purposes you’ve got the badge. You’re done. You know Rails.

Now the more pressing problems and prickly questions around the enterprise, integration and scalability need to be addressed and this is where Ruby is amore compelling story. In fact, things in the Ruby space are really moving forward at break neck speed. It’s not surprising really, given the relatively few Ruby conferences there are each year, that Ruby gets to play out and steal some of Rail’s thunder at RailConf.

So what is going on in Ruby space that’s so interesting?

Ruby Implementations - Where integration is Key

First up there’s JRuby. This is a 100% pure Java implementation of the Ruby programming language. And right there is JRuby’s sweet spot. The ability to seamlessly integrate with the Java platform through Ruby is a big win for some. So running Rails under JRuby and using it as a web gateway into your Java enterprise, together with the ability to leverage mature/known Java tools and the free performance hikes that accompany it has been a very appealing proposition to some. A prime example being the ThoughtWorks Mingle product. Also, having access to the abstract syntax tree which can be shared between multiple Ruby runtimes hosted within the same JVM process is pretty neat and a highly efficient way of managing memory.

MacRuby! As a Mac User I’m excited by this implementation of Ruby 1.9. With MacRuby you can write Mac OS X applications in Ruby without the performance hit typically attributed to standard Ruby and Ruby Cocoa. MacRuby is native to Mac OS X core technologies. Damned quick with all the elegance of Ruby to boot.

IronRuby, backed my Microsoft and sits on top of its Dynamic Language Runtime (check out John Lam’s talk on the DLR), is a .NET implemention of Ruby. IronRuby enables Ruby programmers seamlessly integrate with the .NET platform, in much the same way that JRuby does on the Java platform. Ruby.NET is open source .NET implementation that does not have the same pull as IronRuby.

In fact, the main draw for Ruby developers that target JRuby, MacRuby, Ruby.NET or IronRuby is integration with the Java, Mac OS X or .NET plaforms respectively.

Ruby implementations - Standards are key

Let’s park integration. Let’s focus upon Ruby developers building Ruby apps with an Ruby-oriented environment. Both Rubinius (a spec led Ruby implementation) and MRI/YARV (currently the official Ruby) are competing VMs for running Ruby applications. Everyone started with Matzs Ruby Interpreter (MRI) but now we have many more alternatives. The Yet Another Ruby VM (YARV) project has officially merged into MRI as of May 2008 to combine the best of both worlds to enhance the official Ruby implementation.

RubySpec

But unlike Smalltalk that was really killed by competing implementations, the Ruby community, through RubySpec are collaborating on standards and competing on implementation. This is good. No, hold up, this is great! This will hopefully provide more choice to the developers to select the appropriate Ruby implementation that best fits their solution requirements. Hopefully, this will hold the community together and keep everyone pulling in the same direction. So far, that appears to be the case…

..but then there was Ruby for Scale - Maglev

Maglev is a Ruby implementation built on top of Gemstone’s VM that is written in Smalltalk. Chad Fowler goes into the why and when you would choose to use this Ruby implementation other the others. But the problem is very few people have access to Maglev. It promises the world and come on guys its time to show me the money! The community has seen is a presentation. A damned fine presentation I’m told but Charles Nutter of JRuby is not convinced and other people are already dismissing outright Maglev’s claim to scale. 100 times performance improvement is a big claim. One to watch I guess.

And Finally!

Take a look at the following code snippet:

#!/usr/local/bin/ruby

require 'scalability'

# your code

Now the Twitter guys must be get this all the time. Twitter is growing in size and its architecture will mature and incorporate different technologies I’m sure that best fits their current problems. Time will time. But to say its Ruby’s fault is a little naive at best. That said, wouldn’t it be just great if only you could include scalability in Ruby applications, Java apps, .NET apps, or whatever the platform.

Now, that would be awesome. But the simple fact is you can’t include it, you have design it in. Boooooo say the crowd. Kill joy chant the business. But unfortunately, like so many things in the software industry, you have to go the long way round (read as experience) to get desired results. Because there are no short cuts (read as foolish hacks, or inexperience) on the road to scalability…only blood, sweat and tears! But there are leg ups, tools and techniques and people to assist, but that’s any story for another day…

The Beauty of Ruby

I’m more of a fan of Ruby than Rails. Sure Rails is good, but Ruby is way better. I’m trying to put some time aside to learn a little bit of Polish. As a result, I was a frequent visitor to www.dict.pl. After a couple of days of using this, I’d had enough. Too slow. Too restrictive. Too crap! Time to turn this around.

I wrote a simple English->Polish translator application in Ruby. It does all the usual stuff such as add new words, search for words in either language, and maintain the words in named bundles. The challenge I set myself as a novice Ruby programmer was to implement the core set of features knowing that the code would be fat and not very pretty. I then aggressively sort to refactor the code to reduce its size, whilst increasing the feature set.

The core translation engine started out as 120 lines of code with just the add new word feature. Since then I’ve learnt a lot about how to structure Ruby programs and the effective use of closures, iterators, containers and yaml. In the process, I’ve added search, display and bi-directional features to the translation engine and reduced the lines of code to 114.

I have a new found respect for Ruby the Language. It is the most expressive language I played within in a long time. Also, contrary to what many non-Ruby programmers tell me, Ruby is readable when written well. Unfortunately, on my travels through the web, I have seen some really awful Ruby code and this stuff is truly poisonous. Bad Ruby is completely unfathomable. A ticking time bomb. However, well-written is Ruby is sublime. I truly believe that there are no shades of grey here :-)

Heroku!

I’ve found Heroku!

Heroku allows me to build and deploy Rails applications. It couldn’t have happened at a better time for me because my current provider doesn’t give me what I need re. Ruby and Rails. So I took the following steps:

1) Registered with Heroku
2) When I got my sign-up email, I zipped up my Rails app (removing the .svn directories, tmp and log folders)
3) Uploaded to Heroku
4) Then run it

The application is a re-write of http://www.clevegibbon.com and can be found here http://clevegibbon.heroku.com. I’ll evolve it there.

Heroku is novel. Stunningly simple. Very expressive.

Sweet!

Bully Boy Ruby…

I’ve had an uncomfortable week with Ruby. I’ve been reading blogs, articles and excerpts from books. Scanning irc channels and watching videos on what is ruby and where it is going. However, there is a distinct bullying undertone from this new kid on the block and Java is clearly the target. I don’t understand this mentality.

Yes, I find Ruby liberating as programming language. I find that you can express yourself more succinctly in Ruby than you can in Java. Also, the speed at which you can accomplish stuff keeps me wanting to learn how I can get the most from Ruby. However, when you hear Ruby guys bang on about how ‘crap’ Java is and/or ex Java programmers that have found Ruby but do not have a good word to say about Java anymore, its a bit much. Fine, you think Ruby is better Java. No problem there. But to bash Java, to promote Ruby…

Java is still a major player on the server-side. JRuby is a clear indicator of Ruby standing (not crapping) on the shoulder of giants. JRuby is a great way of scripting your Java applications. Just imagine if IBM had made the forward looking decision to use/create JRuby instead of Jython for scripting its WebSphere Application Server Platform. Now there’s a thought…

In my mind, Ruby is not enterprise ready for the masses. In fact, I would also go so far to say that Ruby is not a language that will appeal to the masses in the same way that Java and .NET do today. Only a few days back, I was playing with Ruby and a Java/.NET programmer sitting next to me blurted out, “ugh, what is that?” That my friend, is Ruby! And no, it was not that my code. It is just that Ruby looks obscure to the untrained eye. When I read my first full page of Ruby code, it was daunting. But that goes after a while. Practice and all that. However, I never that feel when I learnt other languages such as Smalltalk, C, Ada, Eiffel, Objective-C, C++, Java or .NET.

Ruby is a sharp tool, for sharp people. What do you think happens when you put sharp tools in the hands of the masses? The Ruby community needs to be on-hand with the bandages to nurse the us through our first painful exposures to Ruby the language and its tools/frameworks. I hope they do this.

Tags:

RSpec: automated testing and then manual testing. It works!

I think I have caught the Ruby bug (always last to the party cleve, always the last to arrive!) in a big way. In between my day job, I have been reading (Programming Ruby, Agile Web Development with Rails, Everyday Scripting with Ruby) and writing (currently re-writing clevegibbon.com) Ruby. However, today I was seriously impressed with RSpec.

RSpec has come on some over the last few months. Armed with RSpec, today was the first time I’ve completely writing a bunch of new features for a web site, without once using the site directly. Let me put it another way, I didn’t fire up my browser once when developing the new features. It was all done via RSpec and Rails built-in support for functional/integration testing. And when I was happy that I had spec’d out the features and all the examples were passing, I fired up the browser, traversed to the site and hey presto, it worked as specified. I had to really shake myself, because I was preparing myself for a troubleshooting and/or debug session. I was simply not ready for it working as specified. So I now have time to write this blog entry…

Oh, before you go, here is the rspec for my Rails controllers for my new features (there are also some for the models, views and helpers). You can probably work out what I’m doing by just reading it. Nice!

AdminController for authorised users
- should have access to secured pages

AdminController for unauthorised Users
- should be re-directed to the login page

HomeController for all users
- should allow anonymous users access

InprogressController for authorised users
- should have access to secured pages

InprogressController for unauthorised users
- should be re-directed to the login page

LoginController for anonymous users
- should log in a known user and send them to the admin page
- should not permit unknown users to login in

LoginController for authorised users
- should log them out and direct them to the home page
- should log out users who attempt to login with a GET request

RubyController for all users
- should allow anonymous users access

StuffController for all users
- should allow anonymous users access

Finished in 0.260431 seconds

11 examples, 0 failures

New Year Rant on RoR

It’s rare that you read a tech rant and LOL, but this one by Zed Shaw on why he thinks Rails is a Ghetto shows no mercy what-so-ever. Have a read and let me know what you think? There’s always a flip side to everything, seth/jedi, ham/pigs, optimus prime/megatron! I just found the timing funny as I am in the midst of picking up Ruby and RoR.

Oh, please turn off your profanity filters, take a pinch of salt and get comfortable…you’re in for an adults only ride!

From Ruby to Rails

Well I had to dive in and try Rails. Although Ruby is completely independent of Rails, we live in a web-based world, and as a result you can’t talk Ruby with hearing about Rails.

First impressions, pretty cool. To learn it, you need a damned fine book. I wouldn’t recommend poking around on the web and reading Introduction to Rails types of tutorials. I did this and found it to be too time consuming to find out what I needed. Rails is deep and you need to commit the time it takes to read a book to get a rudimentary understanding of what it is all about. Tutorials can’t do this.

Just like in the Java world, if you wanted to learn about servlets, there was one book you just had to read, Java Servlet Programming by Jason Hunter with Will Crawford. For Rails, it’s Agile Web Development with Rails by Dave Thomas and David Heinemeier Hansson, et al. I’m taking my time with this and flicking between the PickAxe book (now in the 3rd edition, ahhh just bought the 2nd).

There’s a lot to learn.