[Python-3000] PEP 3124 - Overloading, Generic Functions, Interfaces, etc. (original) (raw)

Steven Bethard steven.bethard at gmail.com
Wed May 9 22:16:26 CEST 2007


On 5/9/07, BJörn Lindqvist <bjourne at gmail.com> wrote:

I very much prefer the latter version. The reason is because the "locality of reference" is much worse in the overloaded version and because I have found it to be very hard to read and understand overloaded code in practice.

Let's say you find some code that looks like this: def dostuff(ob): yield obj @overload def dostuff(ob : ClassA): for o in ob: for ob in dostuff(o): yield ob @overload def dostuff(ob : classb): yield ob Or this: def dostuff(ob): if isinstance(ob, classb) or not isinstance(ob, ClassA): yield ob else: for o in ob: for ob in dostuff(o): yield ob With the overloaded code, you have to read EVERY definition of "dostuff" to understand what the code does. Not just every definition in the same module, but every definition in the whole program because someone might have extended the dostuff generic function.

I don't buy this argument. That's like saying that I can't understand what len() does without examining every object that defines len(). Do you really have trouble understanding functions like len() or hash()?

STeVe

I'm not in-sane. Indeed, I am so far out of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy



More information about the Python-3000 mailing list