Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python dictionaries are awesome

Reply
Thread Tools

Python dictionaries are awesome

 
 
Steven D'Aprano
Guest
Posts: n/a
 
      11-27-2012
.... 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
 
Reply With Quote
 
 
 
 
Dave Angel
Guest
Posts: n/a
 
      11-27-2012
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

 
Reply With Quote
 
 
 
 
Chris Angelico
Guest
Posts: n/a
 
      11-27-2012
On Tue, Nov 27, 2012 at 1:32 PM, Steven D'Aprano
<steve+> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Python is awesome (Project Euler) Roy Smith Python 6 01-03-2013 02:38 AM
updating dictionaries from/to dictionaries Brandon Python 12 08-15-2008 12:35 AM
Pickling dictionaries containing dictionaries: failing,recursion-style! lysdexia Python 6 12-02-2007 12:03 AM
Awesome Python Information Brandon Python 6 11-08-2006 06:50 AM
python shutting down sloooooooowly/tuning dictionaries Till Plewe Python 0 04-21-2004 03:39 PM



Advertisments