Python's Reference And Internal Model Of Computing Languages

Ryan Kelly ryan at rfk.id.au
Wed Feb 3 03:46:59 CET 2010


> On Tue, 2010-02-02 at 17:28 -0800, Xah Lee wrote:

I know, I know, do not feed the trolls.  But this is just so *wrong*
that I can't help myself.

> In Python, there are 2 ways to clear a hash:

No, no there's not.  There's one way to clear a hash and there's one way
to assign a new object to a variable.

>  “myHash = {}” and
> “myHash.clear()”. What is the difference?
> The difference is that “myHash={}” simply creates a new empty hash and
> assigns to myHash, while “myHash.clear()” actually clear the hash the
> myHash is pointing to.
> 
> What does that mean?? Here's a code that illustrates:
> 
> # python
> # 2 ways to clear hash and their difference
> aa = {'a':3, 'b':4}
> bb = aa
> aa = {}
> print bb # prints {'a': 3, 'b': 4}
> 
> aa = {'a':3, 'b':4}
> bb = aa
> aa.clear()
> print bb # prints {}
> 
> This is like this because of the “reference” concept.

...snip inane babble...

> Languages that do not have any “reference” or “object”, or otherwise
> does not require the programer to have some internal model of source
> code, are: Mathematica, JavaScript, PHP. (others may include TCL,
> possibly assembly langs.)


Just so we're all clear exactly how much thought has gone into this
little rant, here's a transcript from a JavaScript session:

  var aa = {};
  var bb = aa;
  aa.hello = "world";
  alert(bb.hello)  -->  "world"
  delete bb.hello
  alert(aa.hello)  -->  "undefined"

OMFG, references!!

Come to think of it, the JavaScript and Python object models are really
very similar.  I'm genuinely curious now - what little sprinkle of magic
fairy dust has earned JavaScript objects the Xah Lee seal of approval
while Python objects miss out?


   Ryan




-- 
Ryan Kelly
http://www.rfk.id.au  |  This message is digitally signed. Please visit
ryan at rfk.id.au        |  http://www.rfk.id.au/ramblings/gpg/ for details

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/python-list/attachments/20100203/9eed338d/attachment.pgp>


More information about the Python-list mailing list