Does it matter if when explaining assignments like a = 10
or f = <function>
we talk about "assign a value/object to a name" or "assign a name to a value/object"? I was wondering if the latter shows more clearly that a
or f
are labels with stick on an independent value/object?
1 Answer
There is a recent thread on the SIGCSE mailing list about whether assignment uses "labels" or "boxes" as an explanatory mechanism. I actually prefer "references", which is a bit like labels but more abstract. And I avoid boxes like I avoid the pandemic.
To explain assignment, therefore, I wouldn't use the word "assignment" itself, but the word "associate".
Assignment associates a name with a value.
Note "with", not "to" in the description, so being symmetric avoids your dilemma. You can substitute "and" for "with".
Note that the reference model for both objects and primitives is consistent if you keep in mind that the real difference is that some "values" are mutable and some are not.
A given name can be associated with only one value at a time in a given context, but the context may be limited (scope...). The association can be changed or not depending on other factors (const...).
The "name" might be complex (array entries: a[i] = ...) and even involve other associations (i in the previous example).
Note that the "complex" name case, above, starts to break down. But, by the time that you get to arrays in a course, the idea of an assignment will already be so ingrained that the complication is unlikely to arise. If it does, just say that your original metaphor wasn't perfect, as few are.
-
$\begingroup$ "But, by the time that you get to arrays in a course, the idea of an assignment will already be so ingrained that the complication is unlikely to arise." There are many courses on C programming which consider that variables and assignment are a simple concept that will be easily understood by every student, but that pointers and arrays are super complex and won't be understood easily. And indeed students tend to fail when they arrive at the "pointers" part of the course. In many cases, this is due to the course not properly explaining the concept of assignment, so that (...) $\endgroup$– StefCommented Aug 26, 2021 at 13:45
-
$\begingroup$ (continued) so that it's not "ingrained" like you say, by the time the students get to pointers and arrays. $\endgroup$– StefCommented Aug 26, 2021 at 13:45
-
2$\begingroup$ You say that you prefer
reference
tolabel
, but then usename
(Which meanslabel
). Therefore, it looks like you preferlabel
. I also like label: One reason for this is that the label can be associated with a reference, or a value. $\endgroup$ Commented Aug 31, 2021 at 7:13 -
1$\begingroup$ The primitives vs non-primitives distinction is unique to Java: Mutable/immutable, value/reference, and primitive/non-primitive, are all independent concepts, and should be orthogonal in the language design. However, Java (somewhat) ties them together. $\endgroup$ Commented Aug 31, 2021 at 7:18
a
andf
are not abstract labels "stuck on to" a value or an object. They are variables. They are concrete locations in memory into which a value or a reference to an object may be stored, and the assignment represents the run-time action of storing the value or the reference. $\endgroup$