Jump to content

Talk:Value type and reference type

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

Does JavaScript not have value types?

[edit]

According to JavaScript: The Definitive Guide (4th edition): "The types can be divided into two groups: primitive types and reference types. Numbers, boolean values, and the null and undefined types are primitive. Objects, arrays, and functions are reference types." … "Strings are an unusual case." — Preceding unsigned comment added by 2001:464F:23F3:0:D16E:6733:6BA1:273A (talk) 19:02, 8 December 2019 (UTC)[reply]

Article seems to conflate a few different things

[edit]

This article seems to conflate a few different concepts:

  1. Many languages support a special kind of value that points to an abstract memory location. Examples include "pointers" in C and C++ (where &i is a pointer to i — if i has type int, then &i has type int *) and "references" in Perl (where \$i is a reference to $i).
  2. Many languages support a kind of variable that's an alias for an existing entity. Usually this is only supported for function parameters ("call by reference"), but in a few languages it's supported more generally; for example, in C++, int & i = j declares i as a "reference" to j, so any reads or writes involving i are implicitly forwarded to j. (Conceptually, we can imagine i as syntactic sugar for dereferencing a pointer i_ptr that points to j.)
  3. In some languages, some kinds of entities are always implicitly accessed via a pointer/reference. An example is Java, where this is true of objects: Object obj1 = obj2 doesn't create a new object, but rather, it makes obj1 refer to the same object that obj2 currently refers to. This is different from C++ references in that either obj1 or obj2 can subsequently be changed to refer to a different object. Other languages with the same approach include C#, Python, and JavaScript.

These concepts all use the term "reference" in closely related ways (and sometimes the lines between them are a bit blurry); but I think that the terminology of "value types" vs. "reference types" specifically refers to concept #3. The idea is that, in languages like Java, there are some types of entities (non-object types) that can be accessed directly, and other types (object types) that can only be accessed via references/pointers.

So, I'd like to rework this article to specifically focus on concept #3. The article would still discuss #1 and #2, but only with an eye toward elucidating #3 and showing how it relates to concepts in other languages (or even in the same languages: C# has all three of these).

Would anyone object to my doing that? (Normally I'd just "be bold", but in this case it would mean removing a significant proportion of the current content of the article, so I figured it's worth discussing beforehand.)

RuakhTALK
17:42, 29 August 2023 (UTC)[reply]

Addendum: I've now made those changes. —RuakhTALK 23:17, 1 September 2023 (UTC)[reply]