Python's Reference And Internal Model Of Computing Languages
Xah Lee
xahlee at gmail.com
Tue Feb 2 22:36:38 EST 2010
()On Feb 2, 6:46 pm, Ryan Kelly <r... at rfk.id.au> wrote:
> > 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?
Thanks. You are right. I think i put JavaScript there without much
thinking.
Xah
More information about the Python-list
mailing list