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, Ruby, C# and Smalltalk

The Beauties and Beasts of Object Orientation
Thursday 12 April 2007.
 

Why are people with a Pascal background so often attracted to Ruby? On the face of it, Ruby and Pascal could hardly be more different. The one (Pascal) is a compiled language that strictly enforces type-checking and isn’t even object oriented. The other (Ruby) is an interpreted language with a free-and-easy approach to types (not only are there no declarations but a variable can be instantiated to totally different types of object from one line to the next) and, moreover, it’s object oriented from the ground up.

Before going any further, let me explain my programming prejudices. I began programming (seriously) with Borland’s Turbo Pascal in the early ‘80s. In the years that followed I dabbled with Pascal’s successor, Modula-2, flirted with Prolog and digressed into a few C-like languages such as Java and C++ before eventually landing up with Microsoft’s C# - designed, as Fate would have it, by the same man responsible for Turbo Pascal. These days, I program mainly in C# (as I’m one of the developers of Ruby In Steel, a Visual Studio IDE, this is the most convenient language) and Ruby (which happens to the language for which our IDE is written). But I still have that certain ‘Pascal way of thinking’ hard-wired into my brain: the ideals of neat, well-structured, self-documenting, easily-debugged code are second nature to me. When I write in C#, my coding style is, I think, discernibly Pascal-like. When I write in Ruby, the resemblance is probably even more striking...

I’ll have more to say about Pascal and Ruby in another Blog entry. First though, let me digress into the strangely influential history of Pascal and .NET. I remember a talk given by Turbo Pascal’s developer, Anders Hejlsberg, at a Borland Developers’ conference in San Francisco (Now, let me seem how long ago was that? Back in the very early ‘90s, at a guess - or maybe even the tail end of the ‘80s). At the time, Borland had gone ‘object crazy’. The company’s boss, Philippe Kahn, had embraced object orientation with an almost evangelical fervour. Even Borland’s flagship product, Turbo Pascal, would, from now, on, have objects with everything.

Hejlsberg, it seemed, had not been an easy convert. In his talk, he admitted frankly, that when Kahn had suggested adding objects to Pascal, he had been less than enthusiastic. As far as I can recall, the way he put it was that he didn’t want any ‘nasty objects’ in his ‘nice, neat Pascal’. Well, Kahn eventually persuaded him and, as a consequence, a variety of more-or-less object oriented versions of Pascal were subsequently produced for both DOS and Windows.

I have to say that it was at this time that I stopped using Borland’s Pascal products. My impressions were that Hejlsberg has been right all along: those nasty objects only added extra layers of complexity to Pascal and, didn’t provide me (the programmer having to grapple with them) with any obvious benefits.

I was finally won back when Borland launched Delphi. This was to Pascal what Visual Basic was to Basic. It came with a drag-and-drop component library and, with its blend of visual objects and event-driven programming, its object orientation seemed to make some kind of sense.

Many years later Anders Hejlsberg moved from Borland to Microsoft and started work on a class library for a short-lived Microsoft dialect of Java (J++) before moving on to design C#, a language which has elements that will be familiar to both Java and Delphi programmers.

Now just about every language you can think of comes with added objects. In my opinion, most of those languages would be a whole lot better without them. To understand why, you probably need to have at least some experience of a real object oriented language - not one that’s had objects bolted on, but one that’s had objects from its very conception.

I think it was around the time when I gave up on Borland Pascal that I decided to try out Smalltalk. That was an eye-opening experience. After spending a few weeks being largely baffled by the language, I suddenly saw what object orientation was all about and why the version of object orientation implemented by Borland’s Pascal was so unsatisfactory.

In the years since then, I have become more and more dissatisfied with OOP in language such as Java, C# and Delphi. The trouble is that those languages take a few things from Smalltalk (such as inheritance and some aspects of encapsulation) but forget some of the other equally important things (such as proper data-hiding and an environment that fully supports object oriented development).

To understand the difference between Smalltalk’s OOP and that of other languages, you only have to glance at the class library. Smalltalk class hierarchies are generally quite dense, with many levels of descent; those in other languages are generally shallow. But Smalltalk methods are tiny - the average size of a method in the standard Smalltalk class library is reputed to be 7 lines. Methods in the C#, Java and Delphi libraries, by comparison, are huge.

You might expect that Ruby would be much closer to Smalltalk. After all, it too is object oriented ‘from the ground up’. But take a look through some of the popular Ruby class libraries. Methods are often tens of lines long; I’ve even found some that are hundreds and (occasionally) thousands of lines long [1]. To my mind that shows that something, somewhere, has gone very, very wrong.

I’ll have more to say on what I think that may be shortly...

[1] OK, I concede that ’thousands’ may be an exaggeration. ’Hundreds’, on the other hand, isn’t. To be frank, I am not sure how many lines there are in some methods in some people’s Ruby code. Single classes are often thousands of lines in length and (without the help of code folding or keyword..end matching tools), it is frequently difficult or impossible to locate the start and end of an individual method. So my point remains: whether a method is hundreds or thousands of lines long, it’s too darn’ long!

AddThis Social Bookmark Button


Home