A question on modification of a list via a function invocation

Steve D'Aprano steve+python at pearwood.info
Thu Aug 17 23:07:18 EDT 2017


On Thu, 17 Aug 2017 11:19 pm, Rustom Mody wrote:

> What is called ‘call-by-object’ or ‘call-by-sharing’ etc is really an
> acknowledgement of the fact that parameter passing in the OO world along with
> permissible mutation of data-structures is inherently leaky


Leaky of *what*?

What do you think the abstraction is that is leaky?

Call by value leaks. The abstraction is that the argument received by the
function is independent from the value you pass in. But the leak happens when
you pass an array with a billion items, and the compiler makes a copy of the
entire array, and you wonder why you run out of memory.

Call by reference leaks. The abstraction is that the argument received by the
function is the argument you pass to the function. Not just the same, in the
sense of equal, but one-and-the-same. As in, "me myself and I" all refer to the
same person. But the leak happens when you try to pass a literal or a constant
or the result of an expression, rather than a variable, and the compiler
says "Uh uh, you can't do that!"

So what abstraction do you think call by object sharing is making, and in what
way does it leak?




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list