Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #33959 > unrolled thread

Python dictionaries are awesome

Started bySteven D'Aprano <steve+comp.lang.python@pearwood.info>
First post2012-11-27 02:32 +0000
Last post2012-11-27 17:16 +1100
Articles 3 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  Python dictionaries are awesome Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-27 02:32 +0000
    Re: Python dictionaries are awesome Dave Angel <d@davea.name> - 2012-11-27 00:27 -0500
    Re: Python dictionaries are awesome Chris Angelico <rosuav@gmail.com> - 2012-11-27 17:16 +1100

#33959 — Python dictionaries are awesome

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2012-11-27 02:32 +0000
SubjectPython dictionaries are awesome
Message-ID<50b4262a$0$21875$c3e8da3$76491128@news.astraweb.com>
... especially when you consider how some other languages implement them.


http://twistedoakgames.com/blog/?p=925

[quote]
Here’s the hypothetical situation: you’re making a flash game. In that 
game users can create named profiles. You store the profiles, keyed by 
their name, so that you ca- OOPS, you just introduced a bug. What’s the 
problem? The dictionary.
[end quote]




-- 
Steven

[toc] | [next] | [standalone]


#33966

FromDave Angel <d@davea.name>
Date2012-11-27 00:27 -0500
Message-ID<mailman.310.1353994088.29569.python-list@python.org>
In reply to#33959
On 11/26/2012 09:32 PM, Steven D'Aprano wrote:
> ... especially when you consider how some other languages implement them.
>
>
> http://twistedoakgames.com/blog/?p=925
>
> [quote]
> Here’s the hypothetical situation: you’re making a flash game. In that 
> game users can create named profiles. You store the profiles, keyed by 
> their name, so that you ca- OOPS, you just introduced a bug. What’s the 
> problem? The dictionary.
> [end quote]
>
>

(facetious)
Whenever someone tries to create a username that happens to conflict
with a pre-existing attribute, just tell them that username is already
taken.  Just watch out when your user HasOwnProperty tries to delete his
account.
(/facetious)

Namespaces are great, we should have lots of them.  But be very careful
about reusing one without checking to see if it's already inhabited.

When a language design does this sort of thing, it tends to make us
skittish about continuing use of said language.

-- 

DaveA

[toc] | [prev] | [next] | [standalone]


#33967

FromChris Angelico <rosuav@gmail.com>
Date2012-11-27 17:16 +1100
Message-ID<mailman.311.1353996997.29569.python-list@python.org>
In reply to#33959
On Tue, Nov 27, 2012 at 1:32 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> ... especially when you consider how some other languages implement them.
>
>
> http://twistedoakgames.com/blog/?p=925
>
> [quote]
> Here’s the hypothetical situation: you’re making a flash game. In that
> game users can create named profiles. You store the profiles, keyed by
> their name, so that you ca- OOPS, you just introduced a bug. What’s the
> problem? The dictionary.
> [end quote]

Here's a crazy possibility. What if, instead of just the name, you use
"dictkey_"+name as the key? That's unlikely to conflict with anything.
Hey, I wonder if Adobe might even have been able to do that under the
covers! That would have been really easy, wouldn't have cost much, and
would have given full functionality! (Except that you now can't have a
property named "dictkey_foo", but that could be considered a
misfeature - you can use a dictionary as a sort of jump table.)

Python just happened to get it right by sheer luck, of course. No
designer could possibly foresee problems like that.

ChrisA

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web