[Python-ideas] Python Isn't Perfect: adding a 'gotchas' section to the tutorial
anacrolix at gmail.com
Mon Dec 12 14:44:46 CET 2011
> The only people I'd see confused by this are those with significant> C++ experience, where assignment of references does indeed go through> a copy of the object itself.
On Mon, Dec 12, 2011 at 7:59 PM, Masklinn <masklinn at masklinn.net> wrote:
> On 2011-12-12, at 06:11 , Greg Ewing wrote:
>> Richard Prosser wrote:
>>> It seems to me that the essential problem is that of assignment in general, which (I believe) creates a reference on the LHS to the object on the RHS,
>>> I would like to understand the reasoning behind such design decisions but I can't find any 'deep' explanations at present
>>> So if you or anyone else can explain exactly why such odditties are implemented I would be grateful.
>> Python's assignment semantics are only an "oddity" to people
>> whose prior exposure to programming languages is very limited.
>> To anyone familiar with almost any other dynamic language --
>> only unsurprising
> It's not even a question of "dynamic languages", Java and C#
> reference types have exactly the same semantics (assignment copies
> the value part of a type, which is the reference itself).
> The only people I'd see confused by this are those with significant
> C++ experience, where assignment of references does indeed go through
> a copy of the object itself.
>> As for rationale, it comes down to something like this: Copying
>> large chunks of data is expensive, so it makes sense to do it
>> only when you really need to. And experience shows that most of
>> the time you *don't* need to copy things.
> Of course technically that copy could very well be performed
> "on write". This would significantly complexify the runtime as well.
> Python-ideas mailing list
> Python-ideas at python.org
More information about the Python-ideas