Talk:Variable (computer science)

Latest comment: 10 years ago by Wikifan2744 in topic The end of this paragraph makes no sense

Unnamed section edit

See the discussion page Talk:Variable for the common discussion history of Variable (mathematics) and Variable (programming). prohlep (talk) 15:49, 3 October 2009 (UTC)Reply

Dubious edit

The current definition is not correct. It seems to define what an identifier (computer science) is. This difference becomes important when you start to consider scoping, aliasing and life time of variables (and identifiers). For example, the "symbolic name" may go out of scope, but the variable might continue to exists. There might be multiple identifiers bound to the same variable, etc. —Ruud 13:08, 22 June 2011 (UTC)Reply

You seem to suggest it's synonymous with a storage location, which has problems of its own. Where's a good fundamental CS reference when you need one... --Cybercobra (talk) 05:49, 23 June 2011 (UTC)Reply
I did not want to state that explicitly as I'm not sure that is correct either (variables have life time, while storage locations are always there, the semantics of a variable are more complex than that of a storage location). I've added a good number of texts at Programming language#Further reading and Semantics of programming languages#Further reading a while ago. One of those will probably have something useful to say on this. Finkel states that: "Imperative languages (such as Pascal and Ada) have variables, which are named memory locations." —Ruud 13:52, 23 June 2011 (UTC)Reply

Robert Harper recently posted some relevant comments on this issue [1] [2]. —Ruud 20:20, 11 February 2012 (UTC)Reply

Also the article should probably differentiable between what Harper calls "assignables" (i.e. imperative variables) and what I would call "substitutables" (i.e. purely functional variables). —Ruud 14:04, 7 March 2012 (UTC)Reply
I'd recomend not no be too wrapped-up on getting an exact definition in the first sentences. The main ideas to transmit are 1) that a computer variable is built from both a name and a storage space, as opposed to mathematical variables where both the name and the value are always interchangeable; and 2) that the name is the usual way to access the value. Although there are alternate mechanisms and special conditions to use the variable, those should be clarified in a later paragraph or even an introductory "definition" section. The lead should be written for a general audience that may not even be programmers; even if we get some reference definition from Computer Science, that shouldn't be used for the first sentence since it has a different target audience. If we state the above two ideas in a clear way, we will have included 90% of what anybody should know about computer variables. Diego (talk) 14:30, 7 March 2012 (UTC)Reply
Perhaps, yes. But we shouldn't get the definition so wrong that we in fact give the definition of another concept (a previous version of the article essentially gave the definition of an identifier). I'm still trying to get the concept of a variable clear to myself, though. A big problem with variables is that how they work 90% of the time (one memory location with one name) is not at all how they work 100% of the time. A garbage collector might move the variable in memory or a variable might have multiple or no names.* So to me it seems variable is a more elementary concept with associated properties such as a memory location, type and set of names that reference it. I still have to do a more thourough literative review, what's on my shelf mostly concerns itself with the kind of variables you find in the lambda calculus.
* Another problem with this operational view is that the latter could also be phrased as "multiple variables might share the same memory location." Harper's algebraic view – dissecting an imperative variable into a functional variable containing a reference to an assignable – is much more elegant in this respect, but is a novel prescriptive definition instead of the descriptivist definition an encyclopedia should give.
Ruud 15:10, 7 March 2012 (UTC)Reply

Naming Conventions edit

It would be useful to include example naming conventions, eg use of case, whether recommended or imposed for use in specific languages or conventions adopted by organisations. FreeFlow99 (talk) 20:45, 9 August 2013 (UTC)Reply

Scalars edit

Why do we redirect here from "Scalar (computer science)" and not mention scalars anywhere on the page or the discussion? 118.208.247.51 (talk) 09:44, 15 September 2013 (UTC)Reply

I think the term "scalar" as applied to variables and types, is quite language-specific (mainly used for Perl and PHP); it roughly corresponds to "primitive" or "non-composite". It probably deserves explanation, but where? There are several candidate pages:
Rp (talk) 11:36, 16 September 2013 (UTC)Reply

The end of this paragraph makes no sense edit

In the section "Actions on a variable," the last line ("...which value can be changed at run time or execution time is called variable") in the second paragraph [below] makes no sense. The logic of the rest of the paragraph seems to be complete without it. Is it, perchance, just something that has inadvertently remained following a revision? Or does the first part of it possibly belong after the phrase, "...may be associated only with the current value,..."?

"Depending on the type system of a programming language, variables may only be able to store a specified datatype (e.g. integer or string). Alternatively, a datatype may be associated only with the current value, allowing a single variable to store anything supported by the programming language. which value can be changed at run time or execution time is called variable" Wikifan2744 (talk) 06:33, 9 March 2014 (UTC)Reply

Contradiction with another page edit

This page seems to contradict how “parameter” is defined in https://en.wikipedia.org/wiki/Parameter#Computing and https://en.wikipedia.org/wiki/Parameter#Computer_programming.

Variable doesn't have to be in memory edit

I have issue with "In computer programming, a variable or scalar is a storage location (identified by a memory address)". So fully optimized variable that is only stored in a registry is not a variable?