The term "Protocol"

Peter Hansen peter at engcorp.com
Wed Aug 4 23:05:10 EDT 2004


Bruce Eckel wrote:

> Monday, August 2, 2004, 8:44:38 AM, Aahz wrote:
>>Alex Martelli gave an excellent presentation on Design Patterns at OSCON,
>>where he made the point that "interface" is roughly equivalent to syntax,
>>whereas "protocol" is roughly equivalent to syntax plus semantics.  In
>>other words, computer langauges rarely (if ever -- although I suppose
>>Eiffel comes close) enforce protocols in any meaningful way.
> 
> But what would the syntax be in Python? -- there is none. Perhaps you
> mean that in Java a protocol would be an interface plus agreed-upon
> semantics, whereas in Python the protocol would be the agreed-upon
> (e.g. "latent") interface plus the agreed-upon semantics. In a sense,
> both the syntax and semantics would be latent; they would only be
> exposed and tested during use, since there is no formalized way to
> define them.
> 
> In Python, of course, you could simply use a class with "pass" methods
> everywhere to define a protocol. If there were some way to write
> assertions about the protocol you could include those in the class.

My reading of Alex' description seems to be the opposite.  By definining
protocol to include the semantics, you are basically ensuring that an
implementation with "pass" would not be valid, except for a useless
protocol that defined null semantics.  But yes, what you say about the
"latency" is true, and that's how Python works in many areas.  You
need decent automated tests to catch certain errors in Python, though
tools like PyChecker can help with some of the ones that compilers
will find in statically typed languages.

-Peter



More information about the Python-list mailing list