> >> Non-generic function approach:
[snip]
> >> Generic-function approach:
[snip * 3]
> > So you triple the length of the code.
> Yep, for simple things the KISS maxim should be applied.

Returning a jsonified representation of some object is a darn simple thing.

> Actually that example would work by grace of
> jsonify.jsonify_explicit, flexibility...

Yeah, that rule kind of mixes the two paradigms. One is rule based
dispatch, the other implementing the jsonify-protocol.

> Oh, and you might want to jsonify objects built from classes you
> cannot directly modify, like from an C extension. Ok, ok.. you can
> wrap that C extension's object and provide the __json__ method
> yourself... but I *personally* would favor writing a new rule to
> overload a generic function. A matter of taste I guess...

The str() function in Python's standard library has the exact same
problem. It solves that problem by allowing objects to define a
__str__() method. If that method isn't defined it uses its default
stringification code.

> > Why can't they just override __json__()?
> C extension example above.

When was the last time you added a jsonify rule to an object coming
from a C extension?
To clarify, I have nothing against generic functions in general, I
don't know enough about them to criticise them in a meaningful way.
Certainly they have their uses. However, I do know about the jsonify
generic function and in that specific use case, generic functions are
an overengineerd, overkill solution. You just don't jsonify objects
coming from C extensions. You don't add 1500 rules to the function.
You don't (shouldn't) add rules all over the place. And you definitely
SHOULD NOT need a debugger to understand how the damn thing works.

The right solution is a solution similar to how the str() built in
works.  First try calling __json__() on the object, then a number of
if-else statements.

I think it is a common theme in much of Turbogears' code. Cutesy over
generalizations that just complicate stuff, when no generalizations
really are needed. It's not pythonic, it's javaesque.

--
mvh Björn

--~--~---------~--~----~------------~-------~--~----~
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