Python vs. Io

Donn Cave donn at drizzle.com
Sun Feb 1 23:52:44 EST 2004


Quoth LittleDanEhren at yahoo.com (Daniel Ehrenberg):
...
| In your advocacy of Lisp over Forth (something completely unrelated to
| this thread and newsgroup),

My what?

| ... you miss the major selling point of object
| orientation: encapsulation. If you had barks(Dog) instead of
| Dog.bark() (I'm using Python not Io syntax for now), bark() is
| accessible to everyone, not just Dogs. So I could write bark(Cat),
| which shouldn't work.

You're not only using Python syntax, you're using its rules
for function namespaces, and that wasn't exactly what I had
in mind.

In Python, we know that obj.fun() looks for fun in obj, and we
know the reverse is generally true - to invoke fun in obj, we
write obj.fun().  But there are functions like repr or "+" that
end up deferring to their parameters' member functions.  When we
write str(obj) instead of obj.str(), we're hopefully not kidding
ourselves that there's some profound distinction between these two
notations.  Still less in a hypothetical language whose syntax
is different.

There are plenty of cases in anyone's Python code where a plain
function could have been a method of its parameter, or vice versa,
flip a coin.  Why do I have to go through all my code and change
flip(coin) to coin.flip(), or vice versa?  It's an implementation
detail that no one but the implementor should have to care about.

	Donn Cave, donn at drizzle.com



More information about the Python-list mailing list