Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?) Date: Tue, 15 Mar 2016 13:10:33 +1100 Lines: 27 Message-ID: References: <56e44258$0$1598$c3e8da3$5496439d@news.astraweb.com> <8737rvxs89.fsf@elektro.pacujo.net> <87y49muoh6.fsf@elektro.pacujo.net> <56e76b93$0$1616$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de pi0hjo+2DK1rK6CppgexlQBcb9wLiTUqsfnWav+3qkdQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'cpython': 0.05; 'none:': 0.05; 'key.': 0.07; 'type,': 0.07; 'cc:addr:python-list': 0.09; '[1,': 0.09; 'literal': 0.09; 'subject:which': 0.09; 'python': 0.10; '2016': 0.16; 'dictionaries': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hashable': 0.16; 'here).': 0.16; 'integers.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'restricting': 0.16; 'subject:?)': 0.16; 'umpteen': 0.16; 'wrote:': 0.16; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; "python's": 0.23; 'this:': 0.23; 'header:In-Reply-To:1': 0.24; "i've": 0.25; '(which': 0.26; 'switch': 0.27; 'message-id:@mail.gmail.com': 0.27; 'values': 0.28; 'fine': 0.28; 'occasionally': 0.29; '15,': 0.30; "i'd": 0.31; "can't": 0.32; 'statement': 0.32; 'run': 0.33; "d'aprano": 0.33; 'doubt': 0.33; 'option.': 0.33; 'steven': 0.33; 'tue,': 0.34; 'list': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'cases': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'agree': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'where': 0.40; 'some': 0.40; 'your': 0.60; 'subject:The': 0.61; 'more.': 0.63; 'capable': 0.65; 'mar': 0.65; 'bothered': 0.66; 'cut': 0.67; '3.6': 0.84; 'chrisa': 0.84; 'course"': 0.84; 'dict,': 0.84; 'to:none': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc; bh=SrmDbuvVF7iruMiQJDGyRNtUYtm25R7G2Cc5eC6uAXA=; b=aDCoa/+aOqi1rquw7fhaGDu9R0RMRhfS8tvquqbxD8QtZn372vw8VANszL/nhAsy1j 0JPa3hz5JRi/IhyM+d4BuNTmry0Dv9L5Q6ybrzpUf24JwVdvP1E2OSt0Rj9gF+4Rd91O 8XTLGAJbqDK8Dp4QkHSgc/bDwDBsLfdYXuRvQ9jP+mWb8MdL46ElvrZD1YZN6QGmmaTp PMQI+EyDdInrCm1NznMsMwDWvVmfO1VQ9sxpUfLHz6emh+dfN3HHQR939B/iKC2uZzld VC5gKXyfMg0GZ2vbyXDD58ylIdtv6bRfsvg6nJfaBLx+OT5P29PTwvzDsgF4sqD0pAjW EztQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=SrmDbuvVF7iruMiQJDGyRNtUYtm25R7G2Cc5eC6uAXA=; b=Ows/McZtpoZJ4zd35+Zf0DQc1HmRC7pusJIV8y8PsE0KmtWFkBrh5okLtCMXPbYZsu E8OgdKetT6FuxZexVrvERDMVhCecwuc6P3p0UIzPPBG2aVZC1lz88gczfxiTCNgc6wpP Po/IKmlGxZa4jNu+3UdFU6mREEK+PrdwTsRmMPaHpczaF7NwzRiiVY1tjMPWRQ005QmU 1uZ+zDtDBeyv2flTNLR3+rMa4nvsSOZ4titpFI8dgO6gfVQW7So5X1n7yRLy7b7yzr5o ukZwvbYyWCQ/XQo9AJKCFT4mHfjnsR0jii4efRvDtk0oRGImSc5iAHb/nu7J7YQGRIAt fs0g== X-Gm-Message-State: AD7BkJKnJcH5i2lrf0QOxIoCdEhY9SNoEI7JB00EPgt05s1kT80sTk4rPSr9fuSMrDJIc1J+p4nh9J2L/yR51A== X-Received: by 10.51.17.34 with SMTP id gb2mr21050518igd.13.1458007833349; Mon, 14 Mar 2016 19:10:33 -0700 (PDT) In-Reply-To: <56e76b93$0$1616$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:104908 On Tue, Mar 15, 2016 at 12:55 PM, Steven D'Aprano wrote: > But of course, in Python any switch statement would have to support values > of any and every type, not just integers. So any implementation you are > thinking of would have to support cases like this: > > > switch obj: > case "Hello", None: ... > case [1, 2, 3]: ... > case 23.01, 15+2j, Fraction(10, 11): ... > case 100**100, {}: ... > > > and more. This is not negotiable: having a switch statement limited to small > ints is simply not an option. I agree that restricting switch to small ints is not an option; however, is it truly an "of course" that a switch has to "support values of *any and every* type"? IMO it would be fine to require that they be hashable (which would cut out your list and empty dict, but nothing else; and CPython 3.6 is already capable of seeing {1,2,3} and using a literal frozenset, so the same could be used here). I've used Python's dictionaries for umpteen years and only *very* occasionally run into situations where some object can't be used as a key. I doubt that I'd be bothered by a switch statement with the same restriction. ChrisA