Python dictionaries are awesome

S

Steven D'Aprano

.... especially when you consider how some other languages implement them.


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

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]
 
D

Dave Angel

... especially when you consider how some other languages implement them.


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

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.
 
C

Chris Angelico

... especially when you consider how some other languages implement them.


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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top