[Zope3-dev] Proposal: Improving on __implements__
Phillip J. Eby
pje@telecommunity.com
Sun, 19 Jan 2003 10:08:05 -0500
At 04:33 PM 1/19/03 +0200, Steve Alexander wrote:
>Phillip J. Eby wrote:
>>Perhaps the "magic" one should be called 'instancesImplement()'.
>
>I think that would be clearer, especially when people are working with
>classes that themselves implement an interface.
I use this occasionally in PEAK.
>However, for Zope 3, it is far more common to declare that a class'
>instances will implement an interface. Actually, 'far more common' is an
>understatement. This is everywhere. This is also the only kind of
>interface implementation declaration that most application programmers
>will need to use.
>
>So, because it is shorter, I still prefer the bare word 'implements' used
>for saying what instances of a class implement.
I think one other thing that bothers me about 'implements' is that it looks
too much like a language keyword, and I also wonder if it will become one
in some future Python that supports interfaces. I'd almost feel more
comfortable with a word like "offers" or "supports", although I still think
that "explicit is better than implicit", and these "bare words" don't say
*who* is offering or supporting or implementing.
The problem is that they're *expressions*, not statements. So, I expect an
expression that isn't assigned to a name to be an "command" verb, like
"process()". If it's declarative, it seems to me it should be a verb
phrase, like "instancesImplement()" or "instancesSupport()". I expect a
function name like 'implements()' to be a *query*, not a declaration. I
expect it to be either something that returns a sequence (if it's a
plural), or a boolean (if it seems like a true/false thing).
>I'd prefer to keep class statements as class statements. If Python had an
>'instances implement' statement that, for argument's sake is 'implements',
>it might look like this:
>
> class Foo:
> implements IFoo, IBar
>
>So, I suppose I'm trying for something close to that, without needing to
>change the language.
Unfortunately, 'implements(IFoo,IBar)' doesn't look like a statement, it
looks like a boolean test whose return value is being ignored.
>I'd really like to have a syntax that doesn't involve more than one set of
>nested parentheses, and doesn't need to be split onto several lines when
>you want to talk about implementing a number of interfaces, and doesn't
>refer to the '__implements__' name.
How about "implement()"?
class Foo:
implement(IFoo, IBar)
classImplements(IClassicClass)
Also, I *really* don't like the "Like" variants. I'd rather see
'classInterfaces()' and 'instanceInterfaces()':
class Foo(Bar,Spam):
implement(instanceInterfaces(Bar,Spam))
classImplements(classInterfaces(Bar,Spam))
All the functions should return (or accept) iterators.
It's going to be really annoying to import all this stuff from the
interface package all the time; it's the sort of thing that 'from
zope.interface.api import *' ought to be used for, IMO.
'import *' isn't popular with Python experts, and for good reason. But
when the things being imported are going to be part of any non-trivial
application using a particular framework, it's reasonable to use such a
style for the API in question.