The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

Mark Lawrence breamoreboy at yahoo.co.uk
Tue Mar 22 03:44:17 EDT 2016


On 22/03/2016 07:24, Marko Rauhamaa wrote:
> Steven D'Aprano <steve+comp.lang.python at pearwood.info>:
>
>> 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.

I don't recall seeing any reference to "pointers" above.  In fact, I 
don't ever recall seeing references to pointers in the Python docs. 
There's certainly nothing here 
https://docs.python.org/3/reference/datamodel.html

>
>> 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.

I never think about pointers, I think about objects.  Heck, I wouldn't 
have a clue as to how you go about implementing Jython or IronPython in 
terms of pointers.  I don't even know what anybody could mean by that.

>
>> 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...

Whereby these mysterious "pointers" suddenly leap into action I take it?

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence




More information about the Python-list mailing list