Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #31866

Re: Trying to understand OOP (newbie to OOP)

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: Trying to understand OOP (newbie to OOP)
Date 2016-12-14 19:26 +0100
Organization PointedEars Software (PES)
Message-ID <1913588.Icojqenx9y@PointedEars.de> (permalink)
References (3 earlier) <152u4c5l9g1c3og69evu3nre4ov14c3is6@4ax.com> <11687593.uLZWGnKmhe@PointedEars.de> <31305chjkk5nk6utdqkqt6hu4g0b7h9fke@4ax.com> <3306468.kQq0lBPeGt@PointedEars.de> <5ft25c55r32vip25tukphfp7qe5hp89f14@4ax.com>

Show all headers | View raw


John Harris wrote:

> On Tue, 13 Dec 2016 20:23:35 +0100, Thomas 'PointedEars' Lahn
> <PointedEars@web.de> wrote:
>>John Harris wrote:
>>> On Tue, 13 Dec 2016 13:51:28 +0100, Thomas 'PointedEars' Lahn
>>> <PointedEars@web.de> wrote:
>   <snip>
>>>>  var e = {};
>>>>  var f = e;
>>>>  var g = e;
>>>>
>>>>  /* true true true */
>>>>  console.log(e == f, f == g, e == g);
> 
>   <snip>
>>There is only *one* object here, conceptually and its data stored in heap
>>memory.  “e”, “f”, and “g” are merely identifiers of variables, each of
>>which *currently* holds as value a reference to *one and the same object*:
>   <snip>
> 
> Why does the term  e == f  evaluate to true here?

Because (type conversion with “==” notwithstanding; use “===” to avoid this 
condition for anything but +0 vs. -0) “e” and “f” hold the same value.  In 
this case they hold the same reference value, which is therefore referring 
to the same object.  Or, more loosely speaking, they *refer* to the same 
object (but they *are* _not_ objects).  That was easy.

Here is another example:

  var o = {};
  (function (p) { p.answer = 42; }(o));

  /* 42 */
  console.log(o.answer);

If an object (value) would be passed/copied here instead of an object 
reference (value), then “o.answer” would not yield “42”.  Because there is 
no call-by-reference in these languages, only call-by-value, and “p” is a 
local symbol.  (And to assume that the implementation is required to make 
the link from “p” to “o” outside the local execution context, as you did 
before, is outright ridiculous.)

> Let us see what the relevant bits of the current ECMAScript Standard (6th
> ed) say.

Current is the 7th edition, ECMAScript 2016:

<http://ecma-international.org/publications/standards/Ecma-262.htm>

And there have been implementations of editions before that; so, at most, 
what you are quoting applies to previous-to-current versions of 
implementations.
 
> […]
> Sec 7.2.13  Strict Equality Comparison
> 
>   The comparison x === y, where x and y are values, produces true or
                     ^^^
>   false. Such a comparison is performed as follows:
>   ...
>   8. If x and y are the same Object value, return true.
>   9. Return false.

First of all, wrong section for this code.
 
> If there's any doubt about the meaning of "Object value" it is
> ultimately what is returned by the internal function ObjectCreate :
> 
> 
> Sec 9.1.13  ObjectCreate(proto, internalSlotsList)
> 
>   The abstract operation ObjectCreate with argument proto (an
>   object or null) is used to specify the runtime creation of new
>   ordinary objects.
>   ...
>   2. Let obj be a newly created object with an internal slot for
>      each name in internalSlotsList.
>   ...
>   6. Return obj.

Second, there is no definition of “Object value” there.

Third, you could have realized by now that this is deliberately *abstract* 
language and implementations do not follow this to the letter.  Oh wait, 
you did, but only *when it fit your argument*.

“Learn to know what is from what seems to be, and what you wish to be.”
 
> I therefore assert that the ECMAScript Standard does *not* insist that
> the values of e and f are Java-style references.

Nor does it say the opposite.  And Java is by far not the only object-
oriented programming language, nor was it the first of its kind, in which 
objects are handled with references to them.

You just have to start looking above your limited C++ horizon – one 
hopes that this is the reason for your fairytales – where an assignment 
between variables *declared* to be of an object type means something very 
different, and objects are handled very differently (I am just saying 
“object slicing”).

Because it simply does not make sense for an *efficient* implementation to 
create more than one object here inasfar as to allocate memory for the same 
data multiple times *by default* (and you have to go to great lengths to 
really *clone* an object in the languages we are discussing here).  
Especially not when a program is running *within the constraints of 
another*, the Web browser/HTML UA originally.  It makes much more sense to 
pass reference/pointer values around, compare those, and dereference them 
when necessary (property access).  Occam’s Razor.

But go ahead, do memory benchmarks and UTSL, and surprise me with an actual 
finding (instead of your claims based on misconceptions and gut feelings) 
that any implementation of ECMAScript allocates memory for more than one 
*Object* instance here, that it keeps a registry which variable referred to 
which instead of handling references to objects.  Because that would be 
required for your idea to even resemble reality.

I can already tell you one implementation of ECMAScript to which your idea 
does not apply: Mozilla JavaScript.

Hopefully you will *finally* see the light after reading

<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Memory_Management>

(_not_ written by me.)

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Trying to understand OOP (newbie to OOP) bit-naughty@hotmail.com - 2016-12-11 09:48 -0800
  Re: Trying to understand OOP (newbie to OOP) Tim Slattery <tim@risingdove.com> - 2016-12-11 13:48 -0500
    Re: Trying to understand OOP (newbie to OOP) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-12-11 21:47 +0100
      Re: Trying to understand OOP (newbie to OOP) John Harris <niam@jghnorth.org.uk.invalid> - 2016-12-12 10:40 +0000
      Re: Trying to understand OOP (newbie to OOP) John Harris <niam@jghnorth.org.uk.invalid> - 2016-12-12 20:31 +0000
        Re: Trying to understand OOP (newbie to OOP) Tim Streater <timstreater@greenbee.net> - 2016-12-12 21:46 +0000
        Re: Trying to understand OOP (newbie to OOP) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-12-13 13:51 +0100
          Re: Trying to understand OOP (newbie to OOP) John Harris <niam@jghnorth.org.uk.invalid> - 2016-12-13 14:58 +0000
            Re: Trying to understand OOP (newbie to OOP) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-12-13 20:23 +0100
              Re: Trying to understand OOP (newbie to OOP) John Harris <niam@jghnorth.org.uk.invalid> - 2016-12-14 16:42 +0000
                Re: Trying to understand OOP (newbie to OOP) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-12-14 19:26 +0100
                Re: Trying to understand OOP (newbie to OOP) John Harris <niam@jghnorth.org.uk.invalid> - 2016-12-15 14:36 +0000
              Re: Trying to understand OOP (newbie to OOP) John Harris <niam@jghnorth.org.uk.invalid> - 2016-12-14 16:52 +0000
                Re: Trying to understand OOP (newbie to OOP) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-12-14 19:27 +0100
              Re: Trying to understand OOP (newbie to OOP) John Harris <niam@jghnorth.org.uk.invalid> - 2016-12-15 14:48 +0000
                Re: Trying to understand OOP (newbie to OOP) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-12-15 16:16 +0100
                Re: Trying to understand OOP (newbie to OOP) Gene Wirchenko <genew@telus.net> - 2016-12-15 09:28 -0800
                Re: Trying to understand OOP (newbie to OOP) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-12-16 09:07 +0100
                Re: Trying to understand OOP (newbie to OOP) Gene Wirchenko <genew@telus.net> - 2016-12-16 09:06 -0800
                Re: Trying to understand OOP (newbie to OOP) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-12-17 00:33 +0100
                Re: Trying to understand OOP (newbie to OOP) John Harris <niam@jghnorth.org.uk.invalid> - 2016-12-16 10:47 +0000
                Re: Trying to understand OOP (newbie to OOP) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-12-16 17:12 +0100
                Re: Trying to understand OOP (newbie to OOP) Dr J R Stockton <reply1600@merlyn.demon.co.uk.invalid> - 2016-12-17 20:40 +0000
                Re: Trying to understand OOP (newbie to OOP) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-12-18 10:45 +0100
                Re: Trying to understand OOP (newbie to OOP) Dr J R Stockton <reply1600@merlyn.demon.co.uk.invalid> - 2016-12-19 19:15 +0000
                Re: Trying to understand OOP (newbie to OOP) Andrew Poulos <ap_prog@hotmail.com> - 2016-12-20 13:13 +1100
                Re: Trying to understand OOP (newbie to OOP) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-12-20 11:39 +0100
                Re: Trying to understand OOP (newbie to OOP) Andrew Poulos <ap_prog@hotmail.com> - 2016-12-21 07:03 +1100
                Re: Trying to understand OOP (newbie to OOP) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-12-21 00:07 +0100
                Re: Trying to understand OOP (newbie to OOP) Scott Sauyet <scott@sauyet.com> - 2017-01-02 03:55 +0000
                Re: Trying to understand OOP (newbie to OOP) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-01-02 12:26 +0100
                Re: Trying to understand OOP (newbie to OOP) Andrew Poulos <ap_prog@hotmail.com> - 2017-01-02 22:39 +1100
                Re: Trying to understand OOP (newbie to OOP) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-01-02 12:48 +0100
                Re: Trying to understand OOP (newbie to OOP) Tim Streater <timstreater@greenbee.net> - 2017-01-02 11:42 +0000
                Re: Trying to understand OOP (newbie to OOP) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-01-02 12:53 +0100
                Re: Trying to understand OOP (newbie to OOP) Andrew Poulos <ap_prog@hotmail.com> - 2017-01-03 12:02 +1100
                Re: Trying to understand OOP (newbie to OOP) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-01-03 11:36 +0100
                Re: Trying to understand OOP (newbie to OOP) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-12-20 11:37 +0100
                Re: Trying to understand OOP (newbie to OOP) Gene Wirchenko <genew@telus.net> - 2016-12-19 09:43 -0800
                Re: Trying to understand OOP (newbie to OOP) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-12-19 19:55 +0100
                Re: Trying to understand OOP (newbie to OOP) Gene Wirchenko <genew@telus.net> - 2016-12-19 16:05 -0800
                Re: Trying to understand OOP (newbie to OOP) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-12-20 11:28 +0100
                Re: Trying to understand OOP (newbie to OOP) Gene Wirchenko <genew@telus.net> - 2016-12-20 09:44 -0800
                Re: Trying to understand OOP (newbie to OOP) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-12-21 00:03 +0100
                Re: Trying to understand OOP (newbie to OOP) Tim Streater <timstreater@greenbee.net> - 2016-12-20 23:08 +0000
                Re: Trying to understand OOP (newbie to OOP) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-12-21 10:03 +0100
                Re: Trying to understand OOP (newbie to OOP) Gene Wirchenko <genew@telus.net> - 2016-12-20 15:24 -0800
                Re: Trying to understand OOP (newbie to OOP) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-12-21 10:01 +0100
                Re: Trying to understand OOP (newbie to OOP) Gene Wirchenko <genew@telus.net> - 2016-12-21 10:20 -0800
                Re: Trying to understand OOP (newbie to OOP) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-12-22 10:59 +0100
        Re: Trying to understand OOP (newbie to OOP) Tim Slattery <tim@risingdove.com> - 2016-12-13 11:04 -0500
          Re: Trying to understand OOP (newbie to OOP) Jon Ribbens <jon+usenet@unequivocal.eu> - 2016-12-13 16:16 +0000
            Re: Trying to understand OOP (newbie to OOP) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-12-13 17:26 +0100
            Re: Trying to understand OOP (newbie to OOP) Scott Sauyet <scott@sauyet.com> - 2017-01-02 03:58 +0000
  Re: Trying to understand OOP (newbie to OOP) JJ <jj4public@vfemail.net> - 2016-12-12 12:29 +0700
    Re: Trying to understand OOP (newbie to OOP) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-12-12 16:12 +0100
  Re: Trying to understand OOP (newbie to OOP) Scott Sauyet <scott@sauyet.com> - 2016-12-13 02:06 +0000
  Re: Trying to understand OOP (newbie to OOP) bit-naughty@hotmail.com - 2016-12-14 09:33 -0800
    Re: Trying to understand OOP (newbie to OOP) "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-12-14 18:47 +0100
      Re: Trying to understand OOP (newbie to OOP) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-12-14 22:07 +0100
    Re: Trying to understand OOP (newbie to OOP) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-12-14 22:17 +0100

csiph-web