C is fastest

Rajinder Yadav devguy.ca-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
Thu Oct 15 07:25:36 UTC 2009


Yanni Chiu wrote:
> Christopher Browne wrote:
>> You'll find a number of us that haven't "taken the OO kool-aid."
> 
> It's sad if your impression of OO is formulated from C++ and Java. OO 
> was originally conceived of in Smalltalk, and in that environment, 
> objects have a "liveness" characteristic that was a design goal. This is 
>  missing in a dead code environment like C++ and Java, where the code is 
> just text in a file. In Smalltalk, objects are all available to be poked 
> and prodded via inspectors. Even the class object itself can be 
> inspected, just like any other object you've created.

This smalltalk environment sounds similar to the Ruby's Interactive shell (IRB). 
As a C++ developer that is why I think I love Ruby, first because it's truly OO, 
everything is an object. Secondly it's elegant and I can write fewer lines of 
code in Ruby vs C++ and get a lot more done, less error prone, easier to 
maintain and read(assuming less/shorter code in better).

With the Ruby Interactive shell, one can inspect objects, classes, and play with 
them in a environment that allows for quick testing of ideas, learning Ruby or a 
new module/library (Ruby Gem) and building rapid prototypes. Classes are never 
closed in Ruby so you can define, add or remove methods. This is really 
powerful, because if I want to redefine a method add a new one then I don't need 
to worry about having to redeclare the entire static class code like you would 
have to in a language like C++. I just declare the class with the new stuff and 
it gets added on to what was already there in the IRB or a running state.

I can also inject code from modules into the class with a technique called 
mixin, so if I want add Enumeration, I inject the module into my class and I 
have enumeration support and just need to declare a single method which is 
called 'each'. This is one way Ruby gets around the issue of multiple 
inheritance since it's a single inheritance class.

I can even load static code and make it come alive and interact with it inside 
the IRB. The neat thing about Ruby vs C++ is that I don't need to compile and 
link my code, I just type and run. Also if I want to do some heavy lifting I can 
easily call my C++ code from Ruby.


"Tab beautified" Python has a similar test environment.


> To pick up on an earlier critique of OO from someone else (namely that 
> you have to create a class be able to start writing code), this idea has 
> been explored in the Self language. In Self, there is no distinction 
> between classes and non-classes. Everything is just a thing with slots 
> to hold other things. What I've been told is that you start out creating 
> new objects without thinking about classes as you develop your system, 
> and by the time you've finished re-factoring and such, you end up with 
> some objects that pretty much function like classes. These class-like 
> objects end up holding the behaviour that's common for a group of 
> objects. There can still be some objects that don't have an associated 
> class-like object though.
> 

There is a concept like this in Ruby where you create an object and then add 
methods and data to it in a dynamica running state. With cool things like 
reflection using proc objects and lamda functions, you can do some really cool 
stuff passing code-blocks to objects and methods and having those code-blokes 
get executed later, this is more powerful than C/C++ function pointers and 
callbacks, and much simpler to do.

Ruby is a powerful yet beautiful dynamic OO script language, dynamic in the true 
sense of the word. Python has similar features, but not everything is treated as 
an object from what I assume.


-- 
Kind Regards,
Rajinder Yadav

http://DevMentor.org
Do Good ~ Share Freely
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list