Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Marko Rauhamaa Newsgroups: comp.lang.python Subject: Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?) Date: Tue, 22 Mar 2016 09:24:33 +0200 Organization: A noiseless patient Spider Lines: 44 Message-ID: <8737rj561a.fsf@elektro.pacujo.net> References: <56e44258$0$1598$c3e8da3$5496439d@news.astraweb.com> <8737rvxs89.fsf@elektro.pacujo.net> <56e7483d$0$1608$c3e8da3$5496439d@news.astraweb.com> <56f0ebe5$0$1497$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="b7cb1518d23ec19d482dcc9c31d30fdd"; logging-data="28135"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/lYID3Qx2rI7LBZizzuuNJ" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) Cancel-Lock: sha1:UWjAFtMeyRGKZBES85vd8wE/Ig0= sha1:JnnSUjbdfb0mo7438l8Kh35lsi0= Xref: csiph.com comp.lang.python:105447 Steven D'Aprano : > I applaud you writing different versions of code to try different > tactics, but you should start from "write the most natural Python code > you can" *before* you trying guessing what's fast and what's slow. I'm hard-pressed to imagine a situation where I would write *unnatural* Python code for performance gains. Choosing a good algorithm applies to Python programming as well, but convoluted optimization tricks, hardly. > On Tuesday 22 March 2016 11:49, BartC wrote: >> No, it passes only a reference to the entire string. > > In Python terms, that *is* "the entire string". > > The point is, under the hood of the interpreter, *everything* passes > along references. We rarely draw attention to this fact. Given: > > function(1.5, []) > > we say "pass the float 1.5 and an empty list to function", not "pass a > reference to the float 1.5 and a reference to an empty list to a > reference to the function", because that would get rather annoying > quickly. Hm. Annoying to repeat, sure, but I don't know how you could extricate pointers from Python's abstract data model (or Java's, or Lisp's). Prolog or a purely functional programming language could get away without pointers but not Python. > But that's the critical point: it is *behind the scenes*, an > implementation detail. I don't think there is any way to implement, think about or define Python without pointers. > In Python code, you don't pass "a reference to" 1.5, you pass 1.5. > Likewise for all other objects. The abstraction is that you pass > objects around, not references to objects. The devil is in the mutables... Marko