logo

 

     
 
Home
Site Map
Search
 
:: Bitwise Courses ::
 
Bitwise Dusty Archives
 
 
 

rss

 
 

ruby in steel

learn aikido in north devon

Learn Aikido in North Devon

 


Section :: Rants and Raves

- Format For Printing...

Delphi For Ruby? What’s The Attraction?

Is Ruby the new Pascal...?
Sunday 15 April 2007.
 

Take a look at this...

while tired do begin
  tired := hours_asleep < 8;
  hours_asleep := hours_asleep + 1;
  if tired then
     print( 'z' );
end;

OK, now try this...

while tired do
  tired = hours_asleep < 8
  hours_asleep = hours_asleep + 1
  if tired then
     print( 'z' )
  end
end

The first code extract was Delphi (Object Pascal). The second was Ruby. There are, I venture to suggest, a few points of similarity. Which may help to account for the fact, which I noted in a previous post, that Delphi programmers, on the whole, seem to be more attracted to Ruby than to PHP, say, or Perl.

In the two code fragments above, the differences are trivial - an extra begin or end here or there, a := instead of a = plus a few semicolons in the Delphi code.

OK, let me admit that I have cheated to emphasise the similarities. In the Ruby code, I could, for example, have incremented the value of hours_asleep using the C-style += operator instead of the more verbose Pascal-like syntax. I’ve also defined a Delphi print procedure (not shown) to mimic Ruby’s built-in print method. But even allowing for these minor fix-ups, you have to admit that Ruby resembles Pascal much more than C#, Java, C++, Perl, PHP and the rest...

If I really wanted to get obsessive about this I could even add a few semicolons in Ruby (quite legitimate in Ruby syntax) to Pascalize it a bit more. Here goes...

while tired do
  tired = hours_asleep < 8;
  hours_asleep = hours_asleep + 1;
  if tired then
     print( 'z' );
  end
end

Ah, that feels so good...

But then again, I have to admit that it also feels a bit silly. I mean, deliberately programming in Ruby ‘as though it were’ Pascal is a pretty pointless activity. In spite of superficial resemblances, the differences between Ruby and Pascal are far greater than the similarities. For example:

- Pascal is compiled; Ruby is interpreted
- Pascal requires explicit type declarations; Ruby ‘infers’ types (so-called ‘duck typing’)
- Pascal enforces variable declaration; Ruby does not
- Pascal’s constants are constant; Ruby’s (strange but true) are not
- Ruby does metaprogramming (data can be used as code); Pascal definitely does not!
- In Ruby, line-endings are significant; in Pascal they are not
- Ruby is fully object oriented; Pascal isn’t, while Delphi Object Pascal implements a ‘hybrid-OOP’
- Ruby is case-sensitive; Pascal isn’t
...I could go on, and on (and on...)

The plain fact of the matter is that while the syntax of the two languages may appear similar (a sort of pseudo-natural-language style rather than the cryptic curly brackets and operators of the C-family of languages), the resemblance is only skin deep...

And yet, clearly, CodeGear - the development tools offshoot of Borland whose most famous product is Delphi - clearly thinks that there is ‘something about’ Ruby that will appeal to its customers. I’m guessing that the ‘something’ they have in mind may be Ruby’s ‘at first sight’ resemblance to Pascal. CodeGear has said that it plans to release a Ruby development tool later in the year and there is already speculation (though as yet, no confirmation from CodeGear) that the product will go by the name of Delphi For Ruby.

Then again, maybe it won’t. The recently launched Delphi For PHP has not exactly been greeted with choruses of cheering by the Delphi community. The CodeGear newsgroups have, indeed, been filled with largely hostile comments to the effect that “if this thing for PHP is Delphi, then what the heck is Delphi?”

What Is Delphi, Anyway...?

Up to now, most of us who call ourselves Delphi programmers had thought that Delphi was something to do with Pascal - or that variation of Pascal which, until recently, CodeGear had called ‘the Delphi language’. Now, it seems, it’s just a brand name.

Then again, maybe the mistake was in trying to sell a PHP product to Pascal programmers. PHP is, after all, one of those C-like language with all those pesky curly brackets and ‘->’ operators. As every Pascal programmer knows, curly brackets are for comments as ‘->’ operators are for making fun of C++ programmers...

But I digress. Is it really just an accidental similarity of syntax which explains the attractions of Ruby to Pascal programmers? Could it truly be so superficial? Or is there some deeper, more technically compelling explanation?

Let me be honest: I think the attraction is indeed entirely superficial. I will tell you in all honesty that there were two things that first attracted me to Ruby (I speak as a Pascal programmer for over 20 years and a Delphi programmer since the release of Delphi 1.0). First there was its name: Ruby - a nice name; an interesting name; not a pedestrian name like C, C++, C# or Java. And when combined with Rails a fascinating name, Ruby On Rails - an almost poetic name that conjures up both beauty and power.

The second thing that attracted me was its syntax. A ‘simple’ syntax, I thought. An elegant, clear, unambiguous and expressive syntax. As such it surely fulfils the criteria expounded by the inventor of Pascal, Niklaus Wirth, when he spoke of his “Dissatisfaction with presently used major languages”:

"...whose features and constructs too often cannot be explained logically and convincingly and which too often defy systematic reasoning."
(“Pascal user Manual and Report, 2nd Edition” by Kathleen Jensen and Nicklaus Wirth, 1978)

As I learnt more and more about Ruby, I discovered that my first impressions were wrong - expressive it may be; unambiguous it certainly isn’t; elegant and clear it can be but only if used with great care (which, as I’ve discovered, it rather rarely is). In short, for all its virtues, I’d be surprised if Ruby would appeal much to Wirth. Whereas Pascal strives for clarity and simplicity, Ruby often prefers variety and a multiplicity of different ways of doing more or less the same thing. For a simple example, I can honestly say that I’ve lost count of how many ways there are to write a loop in Ruby!

All At C

But at least it doesn’t look like C. So maybe that alone is virtue enough. If you are looking for a language for dynamic web development, Ruby (plus Rails) just ‘looks nicer’ to a Pascal programmer.

The current interest in Ruby can’t all be attributed to its good looks, however. Nor can it be put down to its attractions for Pascal programmers. My guess is that there are more C, C++, C# and Java developers dabbling in Ruby than there are Delphi dabblers. As a C# developer by day (that’s the main language which we use in the development of the Ruby In Steel IDE for Visual Studio) and a Ruby programmer by night, I have some strong views on this matter. But they’ll have to wait for another day and another Blog post...


If you are new to Ruby, you may want to download my free eBook (and source code), The Little Book Of Ruby, which should get you up to speed no matter which language you’ve been using previously.

AddThis Social Bookmark Button

Forum

  • Delphi For Ruby? What’s The Attraction?
    21 April 2010, by Jeff Davis

    It seems like an oxymoron for a programmer to be concerned with how “beautiful” the language is. They’re supposed to be concerned with getting the job done! :)

    Ruby programmers are definitely a different breed. You explained the reasoning well, and I appreciate it. Thank you for your intriguing article.


Home