From: Magnus L. H. <ma...@he...> - 2004-07-27 17:42:09
|
Joerg Lehmann <jo...@us...>: > [snip] > You're right, this should not be the case. Sometimes, however, we > introduced some checks such that the user doesn't get hit by some > strange error when he calls writeEPSfile. Checks are good. I guess I'm just saying that more flexible (i.e. signature-based) checks could be used instead. > For instance, we check whether the arguments passed to some canvas > methods are of a certain type. I don't think this is necessarily > bad. See for instance the insert and set method of the > canvas._canvas class for two examples. The best solution here, IMO, (in an ideal world ;) would be to use either (1) interfaces or (2) protocol adaptation. There are PEPs for both, but I'm not sure whether either will ever become standard Python. (I guess interfaces have the best chance, even though adaptation is much cooler ;) If the API is simple one could check manually (as with the helper functions for strings etc.; you could write similar ones to check whether something seems to be a good canvas). I guess in these cases a simple isinstance might be easier. After all, we *do* have multiple inheritance, so one could always just subclass the needed class as if it were an interface. > > Such type-based discrimination <wink> is in most cases necessary; if > > an object can do the job, just let it. > > > > (Often, using polymorphism directly, i.e. simply calling a method on > > the given object, would be better than using an if statement checking > > properties on the object. That's not feasible in special cases such a= s > > this, where you have to deal with numbers and strings and the like, o= f > > course.) >=20 > Again, you're right - which unfortunately does not mean that the code i= s > perfect in this sense - it developped over quite some time... So if > there are some points where you think the present code can be improved > in this regard, feel free to point them out (or just send a patch). The reason I noticed this was that I saw plenty of isinstance() calls in the linear equation code -- might be inconvenient if one wanted to mix in multidimensional points between the variables and numbers it already knows about, because, basically, the "aren't allowed" in there. No big deal, though. If it turns out to be problematic, I can always fiddle a bit with the code, I guess :) > J=F6rg --=20 Magnus Lie Hetland "Canned Bread: The greatest thing since sliced http://hetland.org bread!" [from a can in Spongebob Squarepants] |