On Apr 23, 2006, at 8:44 AM, Jeff Watkins wrote:

On 23 Apr, 2006, at 11:26 am, Alberto Valverde wrote:
Also I should note that you don't *need* to undersand how they work in order to *use* them.

On the other hand, if you need to understand the code that uses them, you'll NEVER actually know what the code does unless you understand EVERY instance of the generic function. It's impossible to look at the following code any actually know what it does:

@generic()
def flip_the_frobble(obj):
pass

...

def clever_function(obj):
flip_the_frobble(obj)

What does clever_function actually do? It's impossible to tell, because you have no idea what versions of the generic flip_the_frobble have been created.

When languages like C++ offer function overloading, they do it via type inspection. So you can very clearly understand whether the function will be invoked. However, generic functions have no such limitations. I've heard lots of arguments touting that generic functions increase the flexibility of code, and that's certainly true. However, no one has every cited an example that can only be achieved using generic functions. I've yet to hear an explanation similar to: "I've been looking for a way to flip my frobbles for ages, and thanks to generic functions, I now can!"

Most generic function instances use a type or identity check as the predicate.  Even with just plain type checking in languages like C++ you can get lost with deep hierarchies where a function matches a class exactly but also one or more of its superclasses.

There ARE use cases that are best solved by generic functions (or a poor re-implementation of them):

"I've been looking for a flexible way to have a library that can be extended by users, preferably without using adaptation, yet another type registry, or monkey-patching."

There are of course no self-contained use cases that are best done with generic functions, but TG needs to offer extensibility to its users without them having to maintain their own fork.

-bob


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---

Reply via email to