[Python-Dev] Proposal: defaultdict (original) (raw)
Adam Olsen rhamph at gmail.com
Fri Feb 17 23:56:24 CET 2006
- Previous message: [Python-Dev] Proposal: defaultdict
- Next message: [Python-Dev] Proposal: defaultdict
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 2/17/06, Guido van Rossum <guido at python.org> wrote:
On 2/17/06, Adam Olsen <rhamph at gmail.com> wrote: > It's also makes it harder to read code. You may expect d[key] to > raise an exception, but it won't because of a single line up several > pages (or in another file entierly!)
Such are the joys of writing polymorphic code. I don't really see how you can avoid this kind of confusion -- I could have given you some other mapping object that does weird stuff.
You could pass a float in as well. But if the function is documented as taking a dict, and the programmer expects a dict.. that now has to be changed to "dict without a default". Or they have to code defensively since d[key] may or may not raise KeyError, so they must avoid depending on it either way.
-- Adam Olsen, aka Rhamphoryncus
- Previous message: [Python-Dev] Proposal: defaultdict
- Next message: [Python-Dev] Proposal: defaultdict
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]