Wednesday, September 30, 2009

Ruby

I am capturing some conversation from JavaRanch on Ruby:-

Performance Ruby v Java

Ruby vs Java


It would take 5 min to read this as well.

Why Ruby?

Ruby is a strongly, but dynamically, typed, "dynamic," object oriented programming language. That's the official spiel but I suspect that's just a list of buzzwords to many. Being practical, if you're familiar with Python, it's a little like that in terms of its scope (i.e. not high performance, can be used as a "scripting" language, object oriented). Ruby is often called a "pure" object oriented language because everything is an object. This is not strictly true (e.g. a lot of the basic syntax isn't OO) but is a good way to compare it with other languages.

Ruby isn't verbose (if you consider Java to be a 7 out of 10 on the verbosity scale, Ruby's perhaps a 2) and it "gets out of the way" and lets you simply code your logic and features with as little architectural work as necessary (of course, if you want to, you can write Ruby in a very anal way, but it's not necessary to start with).

Inspiration (similar languages)
Python is quite similar to Ruby in some ways, but it's not quite as dynamic and consistent. Ruby takes a lot of influence from Smalltalk, so that's going to be quite similar too.

Major Projects
The Human Genome project uses Ruby and RoR. Check out some slides on the project here
. See this list of some companies that use Ruby/Rails. Frank Carver used a great quote describing Ruby (low ceremony). Ruby feels a lot less like "coding", and more like "trying out ideas".

As far as the Rails framework itself, it's a lot of the things you DON'T do:

configure the webapp
parse xml to objects/ objects to xml/json/html
write a ton of validations
type and tune a bunch of SQL (DDL or queries)
hand-write Ajax or Prototype
bind form elements, parse URL parameters
spend time searching for existing solutions only to have to search out their dependencies (this jar needs these three jars which need...)
pluralize, singularize, capitalize, camelize, humanize, turn into a sentence, format date and time
configure dev v test v prod environments


Plus, you get a lot of advantages that come with using Rails (or gems along with rails):

restful services/web-app urls
easy gem integration
great testing support (unit, functional, integration, performance)
rails application bootstraps (boostrap a: social media site, blog, etc)
a vibrant community
ever expanding platforms (JRuby/Java, IronRuby/.net, etc)
unobtrusive JavaScript (soon)
deployment with capistrano

IDE Support
Aptana RadRails is probably the way to go. It's based on Eclipse. Despite the name it's not just for Rails development and can be used for pure Ruby development if you want. It's a reasonable IDE as long as you like Eclipse

More celebrated is JetBrains' (of IntelliJ IDEA fame) RubyMine but it's a commercial product. I suspect a lot of Java-heads will love it though, and it gets the best reviews overall. I don't use it because I'm cheap.

Ruby In Steel is definitely a good option on Windows. I've given it a go and it feels really nice. Despite not being a Windows user anymore, I still appreciate how well constructed Visual Studio is I wish there were an IDE as good as VS on other platforms. Eclipse just doesn't cut it for me.

Testing
There are a lot of ways to do testing, load testing, and Web application testing from Ruby. The Ruby community seems to be a little bit nuts over testing - almost religious about it - so the number of testing libraries is.. quite large for the size of the community ;-)

One of the best known libraries is Watir. To steal some info: "Watir is an open-source library for automating web browsers. It allows you to write tests that are easy to read and maintain. It is simple and flexible. Watir drives browsers the same way people do. It clicks links, fills in forms, presses buttons. Watir also checks results, such as whether expected text appears on the page. Watir is a family of Ruby libraries. They support Internet Explorer on Windows, Firefox on Windows, Mac and Linux, Safari on Mac, Chrome on Windows and Flash testing with Firefox."

There's also an attempt to port Selenium to Ruby.

If you want something that's lower level and doesn't rely on a browser, there's also WebRat which provides an API for mechanizing Web requests and browser features using Ruby methods. With this you can put together scripts to perform whatever actions are necessary on your sites.

Deployment and Hosting

"Deploying Rails Applications: A Step-by-Step Guide by Ezra Zygmuntowicz, Bruce Tate, and Clinton Begin" is a popular book to understand the deployment process in detail. Here is another link to understand deployment process in Ruby-on-Rails application. Either you use JRuby or not. Mongrel and Apache are the popular Web Servers I know. This link describes the Popular Web Hosts for Rails

Passenger, a.k.a. mod_rails or mod_rack, is the most common way to deploy Rails (and other Ruby web framework) applications nowadays. It works on both Apache and nginx. It's reliable, good with memory, and runs like a champ. It's easy to install on your own Apache-powered server, of course, but some shared hosts run it too, such as Dreamhost. An older technique is to use fcgi/FastCGI. Most hosts are moving to Passenger, but it's still possible to deploy apps via FastCGI and on some setups it works just great.

Conclusion
If Rails is the drug, Ruby is the addiction!!

Resources

  1. http://www.javapassion.com/rubyonrails/ruby_jruby.pdf
  2. http://www.coderanch.com/forums/f-97/Ruby (JavaRanch Ruby Forum)

No comments:

Post a Comment

Thank you for your feedback