An Introduction to Rubyby Colin Steele
Ruby is an object-oriented scripting language that combines the object-oriented programming (OOP) power of Smalltalk with the utility of Perl and the power of Python.
I can already hear you grumbling, "Oh, great, another language." Why should you care? You're already up to your elbows in technologies to learn, right? Well, call your significant other and tell him or her you're going to be late tonight. And go get another Jolt. You're going to be hooked on Ruby for the simple reason that Ruby makes programming fun again (and that's what really counts).
This article introduces Ruby by examining the high-level properties of the language as well as some important features that distinguish it from other languages. We'll compare Ruby with Perl and Python. Along the way, I'll provide my personal take on Ruby, and why I think you'll love it as much as I do.
Traits That Recommend Ruby
Looking down on Ruby from 50,000 feet, we see it has several qualities that recommend it as the next language you should learn, including its consistency and elegance, OOP features, ease of use, extensibility, and its applicability to rapid development.
But what exactly is Ruby? It's a weakly typed, interpreted, cross-platform language implemented in C, written from the ground up to be object-oriented. Ruby's been around since 1995, and has its largest following in Japan, the home of Ruby's author, Yukihiro Matsumoto, a.k.a. "Matz." Although Ruby is more popular in Japan than Python, you may not have heard much about it, yet. Or, if you have, you may have heard that it's a "better Perl than Perl."
I think there's a large measure of truth in that statement. Ruby somehow manages to combine some of the best features of Smalltalk, C, Perl, and Python in a package so elegant and natural that I found myself hooked after just one day.
Some of Ruby's strongest traits are:
Consistency. This is perhaps the single most important trait of Ruby. Like C, Ruby is a small language. It's a simple language, and Matz has made sure that a small set of rules govern its design. The result is Ruby stays out of your way; you don't have to build scaffolding to get it to actually work on the problem at hand.
Elegantly object oriented. Ruby fully supports object-oriented programming, with a from-the-ground-up, internally consistent and straightforward object model. Ruby has all the features you'd expect from an OOPL, including classes, methods, (single) inheritance, polymorphism, class methods, exceptions, and more. These features are designed from the beginning, not glued-on, which means Ruby doesn't have the little inconsistencies and gotchas you'll find elsewhere.
For example, remember when you were learning C++ and the difference between pointer-to-function and pointer-to-member-function bit you on the butt? Or in Perl and Python, where the object (or reference, or string) is passed to your method as the first argument? Or the lack of access controls in Perl. Or.... Well, you get the idea.
Easy to use. Ruby's consistency and its object model make it easy to use. The syntax is simple, clean, and readable, with an expressiveness that gives your code a natural flow. Specific features of the language, such as the ability to pass code blocks on method invocations, make Ruby source wonderfully transparent. There's little of the "line noise" you find in other languages, and although there's also none of the bondage-and-discipline nature you'll find in other languages, Ruby seems to promote a sparse, readable, succinct coding style.
Easy to extend. Using its C-interface extension API, you can create interfaces from Ruby code to existing third-party commercial or noncommercial libraries, or selectively implement methods or classes in a lower-level programming language to improve performance.
Perfect for rapid development. Finally, because Ruby is an interpreted language, it is ideally suited to rapid application development. Write your code, run it, debug it, and run the modified code again--fast, simple, and fun. This low-torque, high-revolution implementation style lets you flow more easily from conception to incarnation as you code. The result can be a surprising increase in your productivity. Although Ruby can be used for large-scale, long-term projects, I now count it as my favorite language for prototyping and spike-solution development.
These aspects of Ruby arise from the design of the language, its purpose, and its heritage. But aside from these more abstract positive qualities, there are several specific language features that you'll want to explore in Ruby. These include code blocks/closures, iterators, variable scoping by name, and its uniform object treatment.
Pages: 1, 2