Talk:Variable

From Wikipedia, the free encyclopedia
Jump to: navigation, search
WikiProject Disambiguation
WikiProject icon This page is within the scope of WikiProject Disambiguation, an attempt to structure and organize all disambiguation pages on Wikipedia. If you wish to help, you can edit the page attached to this talk page, or visit the project page, where you can join the project or contribute to the discussion.
 

Initial comments[edit]

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)

 The term "variable" is also used in scientific experimentation.  I see nothing speaking about an experimental variable here.  My guess is this is *by far* the most commonly used meaning of the noun in the non-math non-computer general population.69.40.254.72 (talk) 15:08, 6 November 2010 (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)

Merge Computer Science split[edit]

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)

Class variable[edit]

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)

Shifting from syntax to semantics[edit]

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)

General Overview[edit]

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. you would have to figure it out 18 divided by 2 = 9. Hence, y=9Ashwariak 18:49, 23 April 2007 (UTC)

Add part on variables in physical sciences, engineering? Split, maybe?[edit]

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?

interpolation: rv example[edit]

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)

pending removal ;; variable name as only way to access value in memory[edit]

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

Extent (lifetime) of a variable[edit]

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)

Controlled Variable, Independent Variable, and Whaaa?????[edit]

Very confused, any insights? —Preceding unsigned comment added by 75.71.249.209 (talk) 21:20, 24 November 2007 (UTC)

IPA transcription[edit]

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)

I agree the IPA notation chosen looks wrong. It also disagrees with the OED entry (which agrees with Furby100's suggestion), hence I'm changing it. —DIV (128.250.80.15 (talk) 05:09, 29 September 2008 (UTC))
Further, the OED puts an optional "ə" before the "l". I'm not sure where WP stands on not ripping off all the entries in the OED, and just how 'optional' the "ə" is, so I haven't added it.
Also, with my browser and browser settings the "r" currently runs into the "ɪə". I've no idea how to fix this, or whether it's an issue for many other readers. —DIV (128.250.80.15 (talk) 05:15, 29 September 2008 (UTC))

Entity[edit]

The article speaks of entity. What is an entity (computer science) (currently red link)? Thanks! --Abdull (talk) 12:07, 9 February 2008 (UTC)

Changing the Lisp code to C++?[edit]

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)

Discrete/continuous not related to level of measurement[edit]

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)

Variables in computing[edit]

The "Computer programming" section was badly written and had some nonsensical or too specific assertions that weren't true for all paradigms. I've tried to generalize and clean it, if you find I've removed something important feel free to discuss. Diego (talk) 12:01, 24 October 2008 (UTC)

A constant is a datum whose value cannot be changed once it is initially bound to a value.[edit]

This feels wrong to me (and I studied computer science). I don't think we call all such values constants; we reserve the term for identifiers that denote a fixed and given value. A final variable is not a constant, and neither is a variable in functional programming! The person who provided the definition may have been confused by C/C++'s çonst keyword, but that keyword doesn't define constants even in C/C++ jargon, if I'm not mistaken. Rp (talk) 01:38, 31 December 2008 (UTC)

You are correct. For example, in the general second degree polynomial ax^2 + bx + c, a, b, and c are constants which can be assigned any (fixed) values, but those values vary from one problem to another. Rick Norwood (talk) 14:27, 31 December 2008 (UTC)

This sentence doesn't ring true to me: In purely functional computer programming, all data are constants, because there is no assignment.
Variables in functional programming are like the x in the ax^2 + bx + c polynomial, they have one single value once they've been bound but it's not always the same one (i.e. it can be different at different function calls). This is different than a,b,c which will have only one value in a given problem, during the complete program execution. Diego (talk) 22:03, 1 January 2009 (UTC)
The sentence talks about data, not variables. Perhaps an overly subtly distinction.
Yes, it is, in my opinion, because it disregards the fact that an encyclopedia should use its terms like a dictionary, i.e. in the senses that they are actually used, rather in a sense that the writer makes up on the spot in order to best match whatever he is trying to describe (as happens in scientific articles). Rp (talk) 12:00, 5 January 2009 (UTC)
Variables in functional languages are not really variables as such, they are simply names that have values are certain points of a programs execution.
Absolutely, but they are universally called variables, and that is what matters in this context. Rp (talk) 12:00, 5 January 2009 (UTC)
Harking back to the discussion of 'final' variables, this usage is really an overload on the term variable. Languages have things called variables and some languages create an entity that is has some of the properties of a variable bt is actually a constant. Perhaps the best idea is to discuss this issue in the article. Derek farn (talk) 01:11, 4 January 2009 (UTC)
Of course variables in FP and logic programming are variables, they are bound during the execution to different values or to partial data structures that become incrementally completed (as the unbound substructures get lazily bound). That sentence would at least be factually incorrect, at worst meaningless. Oh, and "names that have values are certain points of a programs execution" is also what variables are in imperative programming, the only difference is in the lack of assignment operators and referential transparency.
At this point I'd like to see what authoritative sources has to say about the topic. I've never seen something referred as "constant data" as a technical term in programming, "constant" is always a property of variables or objects. Diego (talk) 11:46, 4 January 2009 (UTC)
As far as I know, there is no such technical term, although the notion is well known (as e.g. the const keyword proves). The point is that the term constant in computer science is not usually applied to data, but to identifiers, and more particularly, a constant is a specific type of identifier in most programming languages, with a value that is typically fixed with the program's source code. Rp (talk) 12:00, 5 January 2009 (UTC)
Tokens such as 3 are often called literals or integer literals in language specifications. In C and C++ it can also be a constant expression. Correct usage of the term constant is probably most commonly as an adjective (eg, has a constant value) and this is shortened to constant and used as a noun. Derek farn (talk) 12:29, 5 January 2009 (UTC)

Why don't you fix that one. I'm a mathematician, not a computer scientist. Rick Norwood (talk) 14:21, 2 January 2009 (UTC)

I'll try. Rp (talk) 12:00, 5 January 2009 (UTC)
"Constant" means different things to different people. There's a mathematical joke that "variables don't; constants aren't" -- because a "variable" in a given equation does not vary at all, but merely represents a fixed value that is unknown ... whereas some uses of "constant", such as a constant of integration, may assume any arbitrary value. The point of a constant of integration is to represent that the value of an indefinite integral is a set of functions; it is "constant" only in the sense that it is a real number not dependent upon a variable.
On the other hand there is the use of "constant" to mean a known value that is commonly referred to, such as pi. It is typical to say that pi is a constant. (It is not usually said, but is true anyway, that 3 is a constant!) This sense of "constant" is distinct from the sense in "constant of integration", just as the equation sense of "variable" is distinct from statistics' "random variable" (which do vary).
In a single-assignment language, the value of a variable never varies once established. But it may still be useful to have a distinction between variables (e.g. local variables of a function, which get bound to new values when a function call is evaluated) and constants (e.g. pi, which is always the same in any function or program). And this is indeed the way that programmers working in single-assignment languages use the words: functions have local variables, not "local constants". --FOo (talk) 21:34, 2 January 2009 (UTC)
In most programming languages, 3 is not a constant, in the sense they use the word constant. Your sense of constant does not actually correspond to the way in which the term is normally used when talking about programming languages. This is why I oppose to it being given such prominence in the article: it is highly confusing. Rp (talk) 12:00, 5 January 2009 (UTC)
I was not arguing with you; I was talking about different uses of "constant" and "variable", both in mathematics and in programming. 3 and pi are both "constants" in the sense used in mathematics. --FOo (talk) 07:21, 6 January 2009 (UTC)
They are not known as "constants" in any of the mathematics I've seen (at school or in university). However you are right in that the term constant is often used in mathematics in the sense of a constant factor, and pi may occur there (e.g. in the constants of polynomials). I have rewritten the initial section in the hope of making things clearer, please revise! Rp (talk) 09:06, 6 January 2009 (UTC)
See, e.g., Mathematical constant and, for a mention of 0 and 1 as "constants", Euler's identity#Nature of the identity. The words "constant" and "variable" have lots of uses. --FOo (talk) 09:33, 6 January 2009 (UTC)
Calling 0, 1 or i "constants" is unusual if not incorrect. The definition of constant given in that article is lacking in my opinion: every mathematical constant is a number, but not vice versa. Rp (talk) 20:04, 8 January 2009 (UTC)
In what area are 0, 1, and i not considered constants? Certainly they are considered constants in analysis. Rick Norwood (talk) 14:15, 9 January 2009 (UTC)
Perhaps. From analysis, on which I'm not exactly an expert, I really only know constant terms and related, relative uses of the term. Rp (talk) 00:03, 27 February 2009 (UTC)

Should we mention Finagle's variable constant, which equals the right answer divided by your answer? Rick Norwood (talk) 14:38, 6 January 2009 (UTC)

Not in the present article (which I reached by following Constant (computer science). Rp (talk) 13:51, 9 February 2009 (UTC)

On a related note, the classification of a constant as a particular type of variable pains my sense of terminology. I've always seen them used in opposition: an identifier may be a constant, or a variable, or perhaps something else . Rp (talk) 13:51, 9 February 2009 (UTC)

Naming conventions[edit]

I've been bold and added a lot of unsourced (but I'm quite sure it's not incorrect) information about mathematical variable naming conventions. I hope I haven't gone too far. Leon math (talk) 23:02, 4 January 2009 (UTC)

I've renamed it to "Name Conventions". I don't see the need for there gerund.

I think the stats should be separate article.

SimonTrew (talk) 01:35, 26 February 2009 (UTC)

Split mathematics and CS content in separate articles[edit]

I want to propose to fork this article in two, separating the details for variables in maths to those in computer science. The subtleties are too much for all the exceptions to make sense in a single article. There could be a brief section explaining what both concepts have in common, but the general usage is too different in both areas for them to be explained in a single page. Diego (talk) 12:31, 5 January 2009 (UTC)

Split, but into three parts: mathematics, statistics and computing. Relevant stuff in statistics has been reduced, probably by someone with little connection to stats. Melcombe (talk) 14:30, 5 January 2009 (UTC)
Note added... see Talk:Variable#Add part on variables in physical sciences, engineering? Split, maybe? above.Melcombe (talk) 14:35, 5 January 2009 (UTC)

This article should be an overview, with sections. For example, ==computer science== {main: variables in computer science}

Rick Norwood (talk) 15:25, 5 January 2009 (UTC)

I prefer to keep it as a single article because there are numerous connections and contrasts between the senses of variables in different disciplines. Somebody that wants to read about "variables" in general is likely to want to know about the connections and differences. That said, I admit that the article is not entirely coherent right now. I intend to work on it.

Reddyuday (talk) 11:53, 2 March 2009 (UTC)

I browsed the article for the first time today. I think I agree with Diego above – the article should be split. The similarities between variables in mathematics and computer science are mostly curiosities. They are not very interesting to someone who reads the article from a maths or cs point of view, and I suspect comparing them back and forth would just frustrate such a reader. I think the reader who 'wants to read about "variables" in general' is rare. JöG (talk) 19:50, 4 April 2009 (UTC)

Yes, let's split it up. I think the article now has enough content that a three-way split (mathematics, statistics and computing) makes sense, as suggested by Melcombe. This page should be either a brief overview or a disambigution page. -- Avenue (talk) 22:21, 4 April 2009 (UTC)

Split executed. See Variable (programming) and Variable (mathematics) --Cybercobra (talk) 01:34, 5 April 2009 (UTC)

And, done. Sub-split the math version if 3-way split is still desired. --Cybercobra (talk) 02:06, 5 April 2009 (UTC)
Well done, thanks! Some polishing is still desired, e.g. crossreferencing between them, splitting out Constant (programming), etc. Rp (talk) 07:42, 14 April 2009 (UTC)