Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Mark Lawrence Newsgroups: comp.lang.python Subject: Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?) Date: Sat, 12 Mar 2016 11:27:27 +0000 Lines: 83 Message-ID: References: <87h9gcxkd3.fsf@elektro.pacujo.net> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de jt5Ao/2jNGpfwBuuI1lXYgPuzc6qbGut1PzFaqFj0BZQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'compiler': 0.05; 'from:addr:yahoo.co.uk': 0.05; 'compile-time': 0.07; 'variable,': 0.07; 'lookup': 0.09; 'macros': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:which': 0.09; 'type;': 0.09; 'python': 0.10; 'python.': 0.11; 'stack': 0.13; 'do,': 0.15; 'instead:': 0.16; 'java.': 0.16; 'macro,': 0.16; 'rather,': 0.16; 'really?': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'right:': 0.16; 'say.': 0.16; 'sequential': 0.16; 'subject:?)': 0.16; 'wrote:': 0.16; 'string': 0.17; 'expanded': 0.18; 'found,': 0.18; 'integer': 0.18; 'module,': 0.18; 'tests': 0.18; 'variable': 0.18; 'language': 0.19; '>>>': 0.20; 'ascii': 0.22; 'class,': 0.22; 'constant': 0.22; 'function,': 0.22; 'latter': 0.22; 'lawrence': 0.22; 'simpler': 0.22; 'defined': 0.23; '(or': 0.23; "python's": 0.23; 'this:': 0.23; 'header:In-Reply-To:1': 0.24; 'all.': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints- To:1': 0.26; 'chris': 0.26; 'switch': 0.27; 'executing': 0.27; 'function': 0.28; 'this.': 0.28; 'dramatic': 0.29; 'once.': 0.29; 'structure,': 0.29; 'unlikely': 0.29; "i'm": 0.30; "can't": 0.32; 'table': 0.32; 'expensive': 0.32; 'language.': 0.32; 'statement': 0.32; 'source': 0.33; 'usually': 0.33; 'indexed': 0.33; 'though.': 0.33; 'definition': 0.34; 'could': 0.35; 'unicode': 0.35; 'something': 0.35; 'problem.': 0.35; 'but': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'agree': 0.37; 'operating': 0.37; 'turn': 0.37; 'say': 0.37; 'received:org': 0.37; 'doing': 0.38; "won't": 0.38; 'names': 0.38; 'means': 0.39; 'rather': 0.39; 'to:addr:python.org': 0.40; 'mark': 0.40; 'still': 0.40; 'some': 0.40; 'subject:The': 0.61; 'impact': 0.61; 'charset:windows-1252': 0.62; 'complete': 0.63; 'our': 0.64; 'series': 0.65; 'here': 0.66; 'afraid': 0.67; 'overall': 0.72; 'miss': 0.77; "'class'": 0.84; "'def'": 0.84; '(ie': 0.84; 'enhances': 0.84; 'pythonistas,': 0.84; 'technique.': 0.84; 'different.': 0.91; 'maybe,': 0.91; 'technique': 0.93 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: 80.234.129.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 In-Reply-To: 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:104691 On 12/03/2016 11:08, BartC wrote: > On 12/03/2016 06:48, Marko Rauhamaa wrote: >> Chris Angelico : >> >>> Definitely agree with this. Having a way to declare that a name is >>> "truly constant" would be extremely handy; >> >> I don't think it would be all that handy. I'm afraid all this type >> hinting will turn Python into a poor man's Java. > > It's not type hinting. Otherwise you can say that using 'def' or 'class' > is a form of type hinting. Think of 'const' as operating like the latter > and declaring something a little different. > > Although the volatility of the names so defined is still the problem. > >>> Maybe, but I honestly don't miss 'switch' all that often - and when I >>> do, it's usually because I want a range. >> >> I don't consider the switch statement an optimization technique but >> rather, a readability technique. >> >> Note that Scheme has a "switch statement" (a "case form") despite being >> a highly dynamic language. > > Yes, you can have simpler forms of switch, that have the same overall > structure, but do a series of sequential tests rather than using any > form of table indexed by the value being tested. > > The advantage here is that that test-value need only be evaluated once. > It stays on the stack until some match is found, or the statement comes > to an end. > > It won't have as dramatic an impact on performance, but enhances > readability as you say. > >> Compile-time macros are actually a conceptual compromise that violate >> full-fledged dynamism: once the compiler has expanded the macro, its >> definition can't change. > > What's big deal with dynamism anyway? I could never understand Python's > obsession with it. > > For me, 'dynamic' means that a variable has a dynamic type; that's all. > But you know at compile-time (or when looking at source code) whether a > name is a variable, or a function, class, module, named constant and so on. > > If you need a variable-function, then you just have a variable contain > the name of a function (ie a reference to it). You can bolt on dynamism > /when you need it/. > > OK, mini-rant over... > > >> You're not mistaken. There are no "character constants" in Python. > >> (Note that the definition would be Unicode codepoints, rather than > >> ASCII values.) I don't often miss them, though. > >> Yes, a complete non-issue. > > Really? The issue as I see it is this: > > Writing: a=65 generates this byte-code for the right-hand-side: > > LOAD_CONST 1 (65) An integer > > But writing instead: a=ord('A') generates this: > > LOAD_GLOBAL 0 (ord) > LOAD_CONST 1 ('A') A string > CALL_FUNCTION 1 > > You might be right: doing an unnecessary global name lookup and > executing a function call are unlikely to have any impact on performance... > Function calls are hugely expensive in Python. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence