Sunday, January 02, 2005

Ruby

It is a long time since my last post. I will try to write more regularly this year. Today, I'd like to talk about a programming language which I am really excited about. As I prepared an introductory language tutorial in the last weeks for the OOP 2005 conference I had to intensify my learning and knowledge. The language is Ruby. It was developed 1993 by a japanese guy and originally intended to be a better Perl than Perl. Nonetheless it denotes a pure OO language (whatever that means :-). There are a lot of benefits using Ruby: the language itself, the libraries, the community. What I like most is its combination of different things, OO concepts from languages such as Java, features from Smalltalk and Lisp, and elements taken from scripting languages.

The class above just includes one method. You might pass a block to the method which will then be called within the method's body. In the block the argument passed by the method will be printed to the console. Th example itself is somewhat boring. However, the feature it presents is very powerful. Blocks might be used to implement iterators, threads, or closures, to name just a few examples.

Another fascinating aspect of Ruby is its usage of Mix-Ins instead of multiple inheritance.Suppose, you implemented the following module:

module Mdef info"42" # btw, the last statement in a method also is the return valueendend

In your class you might include the module

class Cinclude Mend

If you now instantiate C you'll be able to use the included method:

c = C.newc.info ==> "42"

Methods will be shared by the class including the module. All instance variables defined within the module will have separate counterparts in the including class. Basically, a class behaves like a singleton class.

0 Comments:

About

If you are a software engineer: DON'T PANIC!
This blog is my place to beam thoughts on the universe of Software Architecture right to your screen. On my infinite mission to boldly go where (almost) no one has gone before I will provide in-depth coverage of architectural topics, personal opinions, humor, philosophical discussions, interesting news and technology evaluations.
(c) Prof. Dr. Michael Stal