re: *very* revised proposal for interfaces

For my purposes, I'm not sure the error checking is really a Good Thing after some of the things Esteban Castro pointed out. If you fail to implement the nesessary methods, that's your own problem. This approach is a lot less work for me, and handles strange cases of late binding more gracefully. Of course a warning would be helpful in the 95% of cases where the assumptions made for error checking are correct.
I think you misinterpret me here. I am not against checking an interface. Indeed, checking would be the only way to detect implicit interface compliance (one of my main points).
from interfaces import ListInterface a = [1,2,3] implements(a, ListInterface) 1 implements(a[0], ListInterface) 0 import my b = my.SuperDuperFakeList() implements(b, ListInterface) 1
It should be possible to define ListInterface once and check it against any arbitrary object, without having to fiddle with, or provide adapters for the type/class of each object that does (de facto) implement it. For example, I don't want to have to do __bindings__ on the list type, UserList, any extension types designed to be used as lists, wrappers or proxies on lists that are not instances of UserList, etc. Declaring that a class implements an interface (this is, it promises that all its instances will satisfy it) still makes sense: * For documentation: declaring compliance with an interface gives a very useful hint on the purpose and usage of the class. * For safety: you may be afraid that satisfying some method signatures alone doesn't guarantee that an object is safe to use in contexts where your interface is required. For example, you have this my.Shape interface with this draw() method. There are too many classes around that provide a draw() method and which won't work for the purposes of my.Shape (and that's why a simple check for draw() is not enough either). Implicit interface satisfaction is not a concern here, because it doesn't make sense that anyone has implemented useful my.Shapes before knowing about your module. So it makes full sense for you to require that any objects that want to implement my.Shape explicitly declare so. This does not necessarily replace checking for draw(). The author of each specific interface must decide her policy on this. * For performance: you may want to cache the results of class checks. You may even do without checking at all, but I don't think this is a good idea. I have my own ideas on how the syntax should be but I'd rather bounce them and let them mature off this list. If anyone is willing to put up a mailing list or just discuss these things privately, please let me know. Esteban.
participants (1)
-
Esteban U.C.. Castro