[Python-ideas] Json object-level serializer (original) (raw)
Cameron Simpson cs at zip.com.au
Sat Jul 31 07:59:12 CEST 2010
- Previous message: [Python-ideas] Json object-level serializer
- Next message: [Python-ideas] Json object-level serializer
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I'm uncomfortable with the foo style proposed. Details and "what I would do" below.
On 30Jul2010 12:06, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote: | Mike Graham wrote: | >Since there isn't really any magic going on, why use a foo name? | >The majority of foo names are for things you shouldn't reference | >yourself || To my mind, the main reason is to avoid name clashes. Protocol | methods often may need to be added to just about any class, | and using a foo name greatly reduces the chance of it | coinciding with some pre-existing class-specific method.
Might not the adder of a class specific method make the same argument? If they really want a class specific method, ought thy not to be using the __foo style, thus avoiding clashes anyway?
The json name make me uncomfortable; to my mind _foo names belong to the language in order to implement/override stuff like [], not to a library hook.
| Anyway, you don't call it yourself in this case either -- it's | called by the proposed json-serialising framework.
I'm curious; what's the special benefit to JSON here? I don't mean JSON is unpopular or horrible, but I can see people going to a xml hook for a proposed XML serialisation framework, and sql for db storage, and ...
I'm doing a little serialisation myself for another purpose. My code gets classes that want serialisation to register themselves with the serialisation module thus:
DB is a NodeDB instance, which can store various objects
DB.register_type(class, tobytes, frombytes)
where class is the class desiring special serialisation and tobytes and frombytes are callables; tobytes takes an instance of the class and returns the byte serialisation and frombytes does the reverse.
No special names needed and no foo special name reservation.
Why wouldn't one just extend the json module with a "serialise this" and "unserialise this" type registry?
Cheers,
Cameron Simpson <cs at zip.com.au> DoD#743 http://www.cskk.ezoshosting.com/cs/
You can listen to what everybody says, but the fact remains that you've got to get out there and do the thing yourself. - Joan Sutherland
- Previous message: [Python-ideas] Json object-level serializer
- Next message: [Python-ideas] Json object-level serializer
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]