Talk:Variable
From Wikipedia, the free encyclopedia
[edit] Initial comments
I made some changes to the "Names of variables" section:
- The section discussed many attributes that belonged in the identifier article. I've reworded and moved a few paragraphs (for example about naming conventions and Lisp symbols) for that reason.
- I replaced the discussion of namespaces by a link to the namespace (computer science) article.
- Changed the section name to "variable names".
-- Eelis 01:17, 2005 May 23 (UTC)
I think the text in the "Computer programming" section of this revision is much more clear and readable than the current text. It is far from perfect but the current text has a lot of bad English and ambiguous sentences, and uses erratic terms, such as "life-time" in place of the standard term "extent". I think it is a better place to work from than the current text. I'd revert -- but I wrote much of the old text and am certainly biased. Anyone else watching? --FOo 05:30, 1 Aug 2004 (UTC)
- It's been almost two weeks with no comment, so I'm restoring several paras of the older version, somewhat improved and better laid-out. --FOo 12:17, 10 Aug 2004 (UTC)
- I think it is a matter of perference. I replaced the old text by a new one for the same reason the old text uses unheard term like extent instead of life-time and is rather unorgainzed and spending too much on somehow irrelevant topics like scoping. There is an article about scope so this article should not spend too much on it. Particularly, the article is making a wrong impression about storage. The key to understand variables is binding. Scopes merely help binding and unbinding process. GC, for instance, has nothing to do with variables. Objects that are not realized by any variable could exist and can be reclamied or not. I believe the new one is far clear on this matter. True, I have removed some parts in the old text so later I will try to merge them into one. -- Taku 03:07, Aug 21, 2004 (UTC)
-
- While I respect your views, I do not believe they are representative of the field we are discussing. The terms scope and extent are in standard use in computer science. [1] [2] [3] [4] The term "lifetime" (not "life-time") is sometimes used as a synonym for "extent", but Google searches suggest it is less common.
-
- You have eradicated several paragraphs of useful discussion of scope and extent, of typed and untyped variables, of function parameters, and storage of variables. While you may believe these are not relevant, they are most certainly related in computer science literature. Garbage collection, for instance, has substantial effects on the way programmers use variables.
-
- I agree with you on the importance of the concept of binding. Please consider working this in to the larger, more complete text rather than deleting wholesale sections that I and others have written. I am restoring the deleted material in parallel with your text. I will be soliciting comment from others who have edited this article recently on how the two can be reconciled. --FOo 01:29, 27 Aug 2004 (UTC)
I have heard both terms lifetime and extent used for variables. I don't think one is particularly more clear than the other, but perhaps they both should be mentioned the first time. I may try to work on the phrasing there, but the english in that whole paragraph is a mess. ("life-time" is a mispelling IMHO.) Also, I think scope should be described in terms of binding, as scope and extent are only related for the special case of local variables, and are not related when refering to static variables, global variables, dynamic variables, class variables, etc... This paragraph is really just a disorganized jumble of concepts. The concepts of scope, lifetime, binding, gc'ing, etc., all need to be defined each in their own paragraph before you try to relate them and mix them together. I think it is very helpful, however, to include (limited) examples of languages that use each technique. The concept of Garbage collection is extremley important. C and assembly programmers will not survive until they understand these things and how they relate to the lifetime of a variable, which may exceed its scope or may be exceeded by its scope. (I.e., passing a reference to a variable that is about to die is a bug. Allowing a reference to go out of scope without freeing its target (and thus ending its lifetime) is a different bug.) Does extent apply to a length of (run)time, a length of code, or both? This needs to be clarified. --ssd 03:31, 27 Aug 2004 (UTC)
- I think this quote from Guy L. Steele's Common Lisp: the Language describes the interplay between scope and extent well:
- [T]he notions of scope and extent are frequently useful. These notions arise when some object or construct must be referred to from some distant part of a program. Scope refers to the spatial or textual region of the program within which references may occur. Extent refers to the interval of time during which references may occur. [5]
- In other words, scope is a lexical fact, but extent a runtime (dynamic) fact. I would go so far as to say that scope has to do with names, extent with bindings of variables to values, and memory allocation with values (or rather, data objects that represent values). If a name is out of scope, you can't even bind it; if it is out of extent, you can't refer to it except to bind it, which gives it a new extent; if its value is still taking up memory when it's out of extent, it's a leak (in C) or garbage (in Java or Lisp).
- When a variable binding extends (in time) as the program's execution passes out of the variable's scope, this is no bug. It is a Lisp closure or a C static variable: when execution passes back into the variable's scope, the variable may be referred to again. But when a variable's extent ends, it becomes unbound -- if it is still in scope, referring to it is an error (or, in C, gets you a nice arbitrary value).
- Extent is related to memory reclamation. When a variable becomes unbound, if its value is occupying storage it must be reclaimed. This is where memory allocation (be it manual or automatic) comes in. In a non-gc system like C, it is a memory leak bug when an object (a data representation of a value) continues to take up storage after no more variables are bound to it. In a gc system like Java or Lisp, it is no bug; the gc reclaims the storage. --FOo 04:57, 27 Aug 2004 (UTC)
- Heh, now to incorporate that nice description into the article... --ssd 00:06, 29 Aug 2004 (UTC)
-
- Hmm, I think you might be misinterpreting that a bit... The extent of a binding has nothing to do with the extent of the value that happens to be bound to it at some point in time (which could be different from what was bound at another point in time). Lisp has a dynamic-extent declaration which can be used to indicate that the extent of the value assigned to a binding is dynamic and the object can be stack-allocated, for example.
I think there needs to be a more clearly defined seperation between variables in CS and variables in mathematics - there is a quite distinct treatment of the two. Perhaps the section for CS can look something like Operator - cover a short paragraph or two on the important topics and leave the important treatment to the respective articles? Dysprosia 11:58, 31 Aug 2004 (UTC)
Hello. I wonder about the reference to Help:Variable in this article. I'm not in favor of self-references within WP but I can see that someone might easily come here looking for special wiki variables. Suggestions? Regards & happy editing, Wile E. Heresiarch 15:57, 25 Jan 2005 (UTC)
[edit] Merge Computer Science split
I merged the two versions of the Computer Science section. Hopefully I have included everything and not offended anybody. The Rod 00:31, 28 December 2005 (UTC)
[edit] Class variable
Class variable redirects here, but the article never defines what it means. Someone feel up to integrating a description? Night Gyr 18:47, 2 March 2006 (UTC)
[edit] Shifting from syntax to semantics
The first part of the article is clear in its adoption of a syntactic perspective on variables:
"a variable is a _symbol_ denoting a quantity..."
The first reference to Computer Science is also consistent with the syntactic view
"in computer science, it _represents_ a place where a quantity can be stored"
However, in the section "Computer programming", the perspective changes and variables becomes things which are denoted rather than denotations:
"a variable can be thought of as a place to store a value"
so, a variable _represented_ a place and now it _is_ a place. The shift in perspective continues with:
"More precisely, a variable binds (associates) a name (sometimes called an identifier) with the location; a value in turn is stored as a data object in that location so that the object can be accessed later via the variable, much like referring to someone by name"
to have a name, a variable must be in the semantics not the syntax.
So where do variables belong? to the syntax or to the semantics?
Both perspective are possible and defendable, but a single one should be consistently adopted to avoid confusion.
Thanks for the otherwise clear contribution.
fabio
(fabio.simeoni@cis.strath.ac.uk) —The preceding unsigned comment was added by 80.41.247.128 (talk • contribs) 2006-03-08 09:56:18 (UTC)
- Most programming languages do not expose the construct which clears up this confusion. That construct is the symbol. The only languages I know of which expose symbols are Lisp dialects (including Scheme) and to a lesser extent Python (in which symbols can be accessed as hash entries).
- Most languages have the idea of a "symbol table", or a lookup table mapping variable names to locations in memory. In Lisp, program code can directly manipulate entries in its own symbol table. For instance, there is a symbol named PRINT. That symbol is a data structure, that contains (among other things) a pointer to a piece of code: a function that knows how to print things. The string "PRINT" is the symbol-name of the symbol; and the printing function itself is the symbol's symbol-function. The symbol serves as a mapping from one to the other.
- In Lisp, you can refer to the symbol itself, by using the quote operator: 'PRINT evaluates to the symbol itself, not to the printing function. This is analogous to the notion of quotation in real-world languages: a cow is a beast with four legs that eats grass; but the word "cow" has three letters and is in English. When you evaluate the word "cow", you ask, "What does the word "cow" mean?" and the answer is the beast with four legs that eats grass. Likewise in Lisp, if you execute (SYMBOL-FUNCTION 'PRINT) you will get a piece of notation representing the printing-function itself.
- In Python, if you define a global variable named "cow", and then look in the hash table returned by the globals() function, you will see an entry where the string "cow" is mapped to the value of that variable. That's the same sort of thing. At a Python prompt, you can confirm this:
>>> cow = "I Go Moo" >>> globals()["cow"] 'I Go Moo'
- In other words, the globals() hash-table is a mapping from strings to values; it is the symbol table. Each entry in it, a key-value binding, is a variable.
- A symbol isn't a variable by itself. In Lisp, you can have symbols that are not bound to any value; they are not variables. If you write 'FOO you are making a symbol with the name "FOO" but no value. If you try to evaluate this symbol -- (EVAL 'FOO) -- you get an error. Likewise in Python, if you enter a string that is not the name of any variable (in the global symbol table or the current local one) you get an error.
- So a variable is really a mapping between a name (a symbol in Lisp, a string in Python) and a value. The name by itself is just a symbol (or identifier in C-ish languages). --FOo 03:09, 9 March 2006 (UTC)
[edit] General Overview
Quote:
- For instance, in the formula: x + 1 = 5, x is a variable which represents an "unknown" number.
It doesn't represent an unknown number, x = 4 Jackliddle 14:58, 30 May 2006 (UTC) I think what they were trying to prove is its not a given fact you have to use your brain to figure out x. I.e. y2 = 18 you would have to figure it out 18 divided by 2 = 9. Hence, y=9Ashwariak 18:49, 23 April 2007 (UTC)
[edit] Add part on variables in physical sciences, engineering? Split, maybe?
As it stands, the article is structured somewhat strangely. There are four paragraphs talking about the term in different fields, then there is a moderately long discussion of the term in applied statistics, a throwaway section on the term in basic mathematics, and then the bulk of the article is about variables in computer science, getting very detailed and technical. If I have time, I might write a section or a part of a section on variables in physical science, but the contents of that section (whether written by me or someone else) will not have much to do with what we've already got on variables in computer science. I think we should split the page into "Variable (applied mathematics and physical science)" and "Variable (computer science)", and possibly also "Variable (statistics)".--Atemperman 20:03, 21 August 2006 (UTC)
- I say "throwaway", of course, to mean that the section is rather stubby and not at the level of detail and thoroughness of the other sections, not that it should be thrown away.
- While I'm in favour of splitting off the computer science content, I'm not clear on the best way of dealing with variables in the sciences. There are big differences in how variables work in mathematics versus statistics, so a split on this basis makes some sense, but they also have a lot in common. I'm less convinced that a split based on application area would be sensible. A split between the natural and social sciences might work, but statistical methods are used in the physical sciences, and some social sciences rely heavily on mathematics (e.g. economics). And biology is a real mixture. Perhaps we should wait until there is enough mathematical/physical stuff to see if there is a real conflict with the statistical/social side. I agree mathematics and the physical sciences could do with better coverage here. -- Avenue 00:10, 22 August 2006 (UTC)
uh...what is the history of the unknown variable?
[edit] interpolation: rv example
The perl example already has two variables ($sName and $sGreet), so there is no need to add a third ($v). The print function is included in the example strictly for display purposes only. Technically it is not relevant to interpolation, at least not in Perl. I will re-edit to make it more clear. Thanks! dr.ef.tymac 14:03, 10 November 2006 (UTC)
[edit] pending removal ;; variable name as only way to access value in memory
Commented out a section that implied variable identifier is the only way to access value (object) in memory. Unless someone wishes to clarify, the content will be removed. Thanks! dr.ef.tymac 17:03, 10 December 2006 (UTC)
you need to rap the variable sentince together to give a complete thought
[edit] Extent (lifetime) of a variable
This article mention of variable extent, and tries to differentiate it from scope, but I think it needs its own section, which at a bare minimum should enumerate the different kinds of extents and their labels in different langauges (i.e., global, static, heap, local, stack, whatever) and how it interacts with the data segment and memory segmentation. --ssd 17:41, 9 March 2007 (UTC)
- Sub-pages at the end of this article now cover most of what I wanted. heap is not listed yet. I suppose I should dig around and find or write something. --ssd 07:06, 21 July 2007 (UTC)
[edit] Controlled Variable, Independent Variable, and Whaaa?????
Very confused, any insights? —Preceding unsigned comment added by 75.71.249.209 (talk) 21:20, 24 November 2007 (UTC)
[edit] IPA transcription
I am not a phonetician, but the IPA transcription doesn't seem quite right to me. It seems to be that the first syllable, transcribed as /vær/, as written, would be pronounced with the vowel of the first syllable of carry, whereas in my experience, it is pronounced like the word care, so I think it should be transcribed more like /vɛər/. I know that accents with the marry-Mary-merry merger will pronounce them the same, but they are distinct for many speakers and the transcription should reflect this. Furby100 07:38, 1 December 2007 (UTC)
[edit] Entity
The article speaks of entity. What is an entity (computer science) (currently red link)? Thanks! --Abdull (talk) 12:07, 9 February 2008 (UTC)
[edit] Changing the Lisp code to C++?
Would it be okay if I changed the Lisp code to C++, seeing as C++ is typically a more widely recognized programming language then Lisp? ShawnStovall (talk) 07:15, 9 April 2008 (UTC)
[edit] Discrete/continuous not related to level of measurement
According to a link on "Measurement theory" at the bottom of the level of measurement entry, "Measurement level has nothing to do with discrete vs. continuous variables." In light of this, I removed the sentence (in the "In applied statistics" section) that said "This [the distinction between discrete and continuous variables] is referred to as the level of measurement."
I also added the "level of measurement" link to the "See also:" links at the bottom of the section.
2rock (talk) 11:29, 17 May 2008 (UTC)