Steven D'Aprano <steve+comp.lang.pyt...@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. > 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 -- https://mail.python.org/mailman/listinfo/python-list