[Python-3000] Abilities / Interfaces

Robert Brewer fumanchu at amor.org
Wed Nov 22 20:16:02 CET 2006


Phillip J. Eby wrote:
> The real problem here is that type inspection violates 
> encapsulation and the whole point of being "object-oriented"
> in the first place.  The point of OO is that it lets you
> *hide* the implementation.  If you put the implementation
> in an if-then branch, you've just lost your OO-ness.
> 
> The reason it's *tempting* to do this in Python, is because 
> we have so many convenient built-in data types that don't
> have application-specific methods.

Grrmbl. It's such a strong temptation, I'm not sure it's worth fighting
in the interests of OO purity. I find myself constantly pushing
teammates to favor builtins over custom types for exactly this reason;
it reduces the overall complexity budget of any application, thus
freeing brain cells to add value (rather than "waste" them striving for
pure OO). And given the ease of subclassing builtin types, I'd rather
standardize on built-in methods than "application-specific" methods;
they meet 99+% of my needs.

> In Java, SMTP.sendmail would be something like this (using 
> Python-like syntax 'cause my Java is rusty):
> 
>      def sendmail(self, from, to_addrs:str, msg, ...):
>          return self.sendmail(from_addr, [to_addrs], msg, ...)
> 
>      def sendmail(self, from, to_addrs:list[str], msg, ...):
>          # main implementation

I have a feeling that the current Python-function-call performance
overhead would outweigh the benefits of this approach in my own code
(which rarely uses more than one isinstance check now).


Robert Brewer
System Architect
Amor Ministries
fumanchu at amor.org


More information about the Python-3000 mailing list