Popular conceit about learning programming languages

Jacek Generowicz jacek.generowicz at cern.ch
Mon Nov 25 08:50:01 EST 2002


"Donn Cave" <donn at drizzle.com> writes:

> |> Perhaps I could be, if message passing were clearer to me!
> |
> | Message passing means that there are several entities that
> | communicate by sending messages between them. The main points are
> | that these entities are autonomous and that there is no central
> | "main" program that controls the behavior of these entitities.
> 
> But what would a message be, precisely?

[...]

> What are the semantics of passing, for the sender and the recipient?

[...]

> Can Python programs be written this way ?

Yes ...

class foo:
    def bar(self):
        print 'This is an object of type "foo" responding to the message "bar"'

class zot:
    def bar(self):
        print 'This is an object of type "zot" responding to the message "bar"'


f = foo()
z = zot()

# Pass message "bar" to the object f.
f.bar()

# Pass message "bar" to the object z.
z.bar()

> How is it different from calling a subroutine? 

When you call a subroutine, you are calling a specific piece of
code. The caller decides what will be executed. When you pass a
message, the decision as to which exact code should be executed is
made elsewhere (some form of dispatch).

But it looks as if my understanding of message passing is different
from Pascal's.



More information about the Python-list mailing list