I recently committed a patch to desktopcouch in which I was using the
bulk update (db.update) method to allow a number of documents to be
updated at once. After I committed the following was brought to my
attention:
Returning exception instances is not pythonic.
Which is actually true. One of the people (aquarius) involved in the
conversation (conversation url: https://code.launchpad.net/~mandel/desktopcouch/batch_update/+merge/17482)
went to #python on irc and had a long chat regarding the matter
(please read it at https://code.launchpad.net/~mandel/desktopcouch/batch_update/+merge/17482).
Since the patch uses the update method from python-couchdb I was
wondering what ware the different thoughts of the people in this list
and what would be the optimum solution.
Kr,
Mandel
On Fri, Jan 22, 2010 at 11:37, Mandel <eti...@gmail.com> wrote:
> Returning exception instances is not pythonic.
By whose standards? Just because Stuart says so?
> Which is actually true. One of the people (aquarius) involved in the
> conversation (conversation url: https://code.launchpad.net/~mandel/desktopcouch/batch_update/+merge/17482)
> went to #python on irc and had a long chat regarding the matter
> (please read it at https://code.launchpad.net/~mandel/desktopcouch/batch_update/+merge/17482).
AFAICS, the point is that we have this list of documents, and we have
to fine-grainedly report if the update succeeded or not. My first idea
would be to just return a list of booleans indicating success or
failure. Throwing an Exception isn't really an option, since it's not
fine-grained (and once thrown the rest of the results aren't checked,
or the results can't be inspected by the caller. Now, here we have the
problem that we can also detect several *kinds* of problems per
failure, so you have to distinguish those somehow. You'd have to use
some sentinel values (constants), so why not use Exception instances?
I actually think it's a rather elegant solution, and certainly not unpythonic.
Cheers,
Dirkjan
--
You received this message because you are subscribed to the Google Groups "CouchDB-Python" group.
To post to this group, send email to couchdb...@googlegroups.com.
To unsubscribe from this group, send email to couchdb-pytho...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/couchdb-python?hl=en.
Hi Mandel,
By whose standards? Just because Stuart says so?
On Fri, Jan 22, 2010 at 11:37, Mandel <eti...@gmail.com> wrote:
> Returning exception instances is not pythonic.
> Which is actually true. One of the people (aquarius) involved in theAFAICS, the point is that we have this list of documents, and we have
> conversation (conversation url: https://code.launchpad.net/~mandel/desktopcouch/batch_update/+merge/17482)
> went to #python on irc and had a long chat regarding the matter
> (please read it at https://code.launchpad.net/~mandel/desktopcouch/batch_update/+merge/17482).
to fine-grainedly report if the update succeeded or not. My first idea
would be to just return a list of booleans indicating success or
failure. Throwing an Exception isn't really an option, since it's not
fine-grained (and once thrown the rest of the results aren't checked,
or the results can't be inspected by the caller. Now, here we have the
problem that we can also detect several *kinds* of problems per
failure, so you have to distinguish those somehow. You'd have to use
some sentinel values (constants), so why not use Exception instances?
I actually think it's a rather elegant solution, and certainly not unpythonic.
Cheers,
Dirkjan
--
You received this message because you are subscribed to the Google Groups "CouchDB-Python" group.
To post to this group, send email to couchdb...@googlegroups.com.
To unsubscribe from this group, send email to couchdb-pytho...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/couchdb-python?hl=en.
Well, the handling of exceptions is clearly application-defined. Here,
too, how to handle multiple exceptions should be left to the
application; someone will have to make a decision on what to do with
conflicts, for example. I don't think the multiple-exception case is
really all that different from the single-exception case, though; if
you know what to do when you get a conflict from a single document
update, you just have to multiply that action by the amount of
conflicting documents for the multiple document update case.
> I agree with it but that does not mean there is not a better way.
Maybe not, but I haven't heard a better proposal yet. :)
Cheers,
Dirkjan