Ruby Impressions

Adam Spitz adamspitz at bigfoot.com
Sat Jan 12 04:23:21 CET 2002


Paul Boddie wrote:

> Although I would probably get used to it eventually, the use of
> "initialize" rather than "__init__" seems to demand more effort (if
> not really any more typing), especially for those of us who don't have
> US English as our first language. ;-)

Fun thing is, Ruby lets you solve the problem. :) Take a look at a
discussion I had with some Python guys at
http://c2.com/cgi/wiki?PythonRubyInitializer - we were solving a
different problem, but it'd be easy enough to name the method "init",
so that you could write:

class Person
  init(:name, :age, :gender) do
    doMoreStuff()
  end
end

instead of:

class Person
  def initialize(name, age, gender)
    @name, @age, @gender = name, age, gender
    doMoreStuff()
  end
end

(Notice that the top version doesn't force you to type out
"initialize", and also doesn't force you to type out "name, age,
gender" three times. That's a little annoyance that I've had to live
with in every language I've ever used, including Python - but Ruby
lets me fix it.)

On that Wiki page, we tried to come up with a Python version of this,
and came pretty close, but I have a suspicion that nobody would ever
use the Python version, because Python forces you to put it way down
underneath the class definition, which is a really weird spot for it.
In contrast, I've been using the Ruby version in all my Ruby code for
the last month and I absolutely love it. I never want to go back.

OK, so it's probably not such a big deal. :) Still, if someone here
could manage to write a Python version that people would actually use,
you'd be one step closer to having at least one more Python convert.
:)


Adam Spitz



More information about the Python-list mailing list