[Python-ideas] Json object-level serializer

Greg Ewing greg.ewing at canterbury.ac.nz
Sat Jul 31 03:17:41 CEST 2010


Antoine Pitrou wrote:

> Sure, generic functions as a paradigm appear more powerful, more
> decoupled, etc.

In this case there's a sense in which using a generic function
could be seen as *increasing* coupling.

Suppose I write a class Foo, and as a convenience to my users,
I want to give it the ability to be json-serialised. If that
is done using a generic function, then I need to put a call
in my module to register it. But that makes my module dependent
on the json-serialising module, even for applications which
don't use json at all.

The alternative is just to provide the function but don't
register it. But using that approach, every application that
*does* use json would be responsible for registering all the
functions for all the classes that need to be serialised,
including those in library modules that it may not be directly
aware of. This doesn't seem like a good situation either.

-- 
Greg



More information about the Python-ideas mailing list