Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.024 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'context': 0.04; 'interpreter': 0.05; 'differently.': 0.07; 'function,': 0.07; 'python': 0.08; 'dict': 0.09; 'immutable': 0.09; 'run.': 0.09; 'am,': 0.12; 'cache,': 0.16; 'function?': 0.16; 'predictable': 0.16; 'pythonic': 0.16; 'replaces': 0.16; 'language': 0.16; 'wrote:': 0.18; 'seems': 0.20; 'memory': 0.21; 'input': 0.22; 'header:In-Reply-To:1': 0.22; 'feb': 0.22; 'knowing': 0.23; 'produces': 0.23; 'convert': 0.25; 'structure': 0.26; 'code.': 0.26; 'stuff': 0.26; 'function': 0.27; 'code,': 0.28; 'order.': 0.28; 'script': 0.28; 'message-id:@mail.gmail.com': 0.29; 'pm,': 0.29; 'argue': 0.30; 'hash': 0.30; 'received:209.85.210.46': 0.30; 'received:mail-pz0-f46.google.com': 0.30; 'varies': 0.30; 'chris': 0.30; 'nobody': 0.31; 'pretty': 0.31; 'source': 0.32; 'minor': 0.32; 'that,': 0.32; "isn't": 0.33; 'object': 0.33; 'fri,': 0.34; 'rather': 0.34; 'anything': 0.34; 'keys': 0.34; 'to:addr:python- list': 0.35; 'something': 0.35; 'requirements': 0.37; 'to:name :python-list': 0.37; 'created': 0.37; 'run': 0.37; 'received:google.com': 0.37; 'another': 0.37; 'either': 0.37; 'received:209.85': 0.38; 'uses': 0.38; 'back.': 0.38; 'could': 0.38; 'some': 0.38; 'think': 0.38; 'should': 0.38; 'data': 0.38; "i'd": 0.39; 'introduced': 0.39; 'received:209': 0.39; 'being': 0.40; 'put': 0.40; 'to:addr:python.org': 0.40; 'type': 0.61; 'more': 0.61; 'your': 0.61; 'results': 0.64; 'ever': 0.64; 'series': 0.67; 'exact': 0.68; 'safe': 0.70; 'care': 0.71; 'factory': 0.73; 'guaranteed': 0.77; '100%': 0.82; 'contiguous': 0.84; 'different.': 0.84; 'nathan': 0.84; 'ubiquitous': 0.84; 'hit.': 0.91; 'promised': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=jFNT9v/pstDqmwsVzyOf9VY2aMVohkyKJ4U6aN2XRmc=; b=Z2ecC/fwfYHMZd7B2E5/Q9JuqRzJWPOXLS2T1yG5cMfUQUBjegQQT4T9iw7NuoVm+2 aW0OSukw0bzkCLWo4zWiNWCGqZt58jz+hr9pOHkNLXpg7Kixx00N+KWGRpGNIWSfF5zT k33yGV/JSdNxP0U2SYPSlY83bk9bxFKYrF9G4= MIME-Version: 1.0 In-Reply-To: References: <4F332007.9080800@wisc.edu> <4f3471e9$0$29986$c3e8da3$5496439d@news.astraweb.com> Date: Fri, 10 Feb 2012 11:53:08 -0500 Subject: Re: frozendict From: Nathan Rice To: python-list Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 44 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1328892792 news.xs4all.nl 6966 [2001:888:2000:d::a6]:42227 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:20173 On Fri, Feb 10, 2012 at 5:08 AM, Chris Angelico wrote: > On Fri, Feb 10, 2012 at 1:30 PM, Nathan Rice > wrote: >> The only thing needed to avoid the hash collision is that your hash >> function is not not 100% predictable just by looking at the python >> source code. =A0I don't see why every dict would have to be created >> differently. =A0I would think having the most ubiquitous data structure >> in your language be more predictable would be a priority. =A0Oh well.... > > It's perfectly predictable. If you put a series of keys into it, you > get those same keys back. Nobody ever promised anything about order. > > If your hash function is not 100% predictable, that means it varies on > the basis of something that isn't part of either the Python > interpreter or the script being run. That means that, from one > execution to another of the exact same code, the results could be > different. The keys will come out in different orders. I think having a hash function that is not referentially transparent is a bad thing. Basing your language on a non-deterministic function? Yeah... A type factory that produces the dict type on interpreter initialization (or, replaces the hash function, rather), and uses time/system information/etc would solve the problem, while limiting the introduced non-determinism. I don't care if the order of iteration for keys is different from interpreter run to run. I have used frozenset(mydict.items()) when my requirements dictated. It is a minor performance hit. Lets also not forget that knowing an object is immutable lets you do a lot of optimizations; it can be inlined, it is safe to convert to a contiguous block of memory and stuff in cache, etc. If you know the input to a function is guaranteed to be frozen you can just go crazy. Being able to freeze(anyobject) seems like a pretty clear win. Whether or not it is pythonic is debatable. I'd argue if the meaning of pythonic in some context is limiting, we should consider updating the term rather than being dogmatic. Just my 2 cents... Nathan