Books I'd like to see

Dave Benjamin ramen at lackingtalent.com
Mon Nov 17 13:29:10 EST 2003


In article <z86ub.43512$hV.1671801 at news2.tin.it>, Alex Martelli wrote:
> Dave Benjamin wrote:
> 
>> Ruby certainly claims to be more OO (and if Smalltalk is your definition
>> of OO, it's a logical conclusion). Of course, everyone has a different
>> definition of what OO really is. Including Alan Kay. =)
> 
> I'm familiar with Ruby's claims, but, as methods/functions aren't really
> first-class objects there, I don't necessarily buy into them.

Well, they are, sort of:

irb(main):005:0> 'hello, '.concat('world')
=> "hello, world"
irb(main):006:0> say_hello_to = 'hello, '.method(:concat)
=> #<Method: String#concat>
irb(main):008:0> say_hello_to.call('world')
=> "hello, world"

However:

irb(main):007:0> say_hello_to('world')
NoMethodError: undefined method say_hello_to' for main:Object

Does not work as you would expect it to in Python. So, basically, a method
is a first class object, because it's a method object, which is an object
just like any other. But a method is not a function, because it's not
directly callable. Functions don't really exist in Ruby; everything is a
method of some object.

So, I suppose it's not surprising that you have to use a "call" method to
call a method object, though I'd sincerely prefer the ability to use
operator overloading on () to eliminate this.

In Python, the same code could be written like this:

>>> say_hello_to = 'hello, '.__add__
>>> say_hello_to
<method-wrapper object at 0x4021974c>
>>> say_hello_to('world')
'hello, world'

Because of Python's simpler syntax for creating and calling method objects,
it provides a more seamless integration of functional/procedural and OOP. On
the other hand, directly callable objects are more like functions (or
closures) than objects, by Alan Kay's definition of objects as entities that
respond to messages (one of which potentially being "call").

One might argue that Ruby is more object-oriented in this respect.

I think it's mostly a syntax issue, but at least for me, Python's method
object syntax is more intuitive and its usefulness is more obvious. Even if
both languages accomplish essentially the same result, Python seems more
consistent in this regard.

>>>> other hand, if you already knew OOP from another language, then you
>>>> are an experienced enough programmer and you can learn Python from
>>>> the Nutshell, isn't it?
>>> 
>>> But the Nutshell only gets into OO _after_ it has covered functions, flow
>>> control, etc; it doesn't _start_ from OO, which is the original poster's
>>> request.
>> 
>> Was this a conscious decision? If so, what were your motivations behind
>> procedural-first vs. objects-first?
> 
> You can productively use Python without understanding nor using 'class'.
>
> Sure, you'll be defining and using objects all the time, but that's much
> like Monsieur Jourdain's "speaking prose for over forty years" without
> knowing he was doing so... not necessarily an issue.  On the other hand,
> functions and flow control (and other minutiae:-) _are_ indispensable, so,
> there would be nothing truly gained by introducing 'class' before them.

Seems reasonable to me. It doesn't make much sense to teach the creation of
classes before the creation of functions (since you'd need to know how to
build a function anyway), but a diehard OOP fan would argue that this is
merely the result of the fact that our current languages insist on using
procedures "under the hood" to define objects, though procedures aren't
really part of the definition of an object. How would you make an object
without procedures? I don't really know, but then, I was taught procedural
first before I was taught OOP, so I'm corrupted like the rest of us. ;)

Still, there are other proponents of "objects first"... I dug up this thread
last week, which is what prompted me to ask you about your motives:

http://lists.bluej.org/pipermail/bluej-discuss/2002-June/001218.html

Cheers,
Dave

-- 
.:[ dave benjamin (ramenboy) -:- www.ramenfest.com -:- www.3dex.com ]:.
: d r i n k i n g   l i f e   o u t   o f   t h e   c o n t a i n e r :




More information about the Python-list mailing list