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:
'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.
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