Thread: this will sound like a stupid question. But what exactly is a Variable?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    71

    this will sound like a stupid question. But what exactly is a Variable?

    I know that this question sounds like when a person who is unaware of Chess asks what a pawn is, but believe it or not I've been writing code for years. I just don't have a proper background in computer science, and that's probably part of the reason why I never learned the proper textbook definitions of all these concepts. (Either that or I was too lazy to make an effort to understand the inner workings of what I was doing.)

    For example, recently, instead of accepting that a reference type variable is just a representation of a memory address, I've been banging my head against the wall trying to understand why authors and other 'authorities' refer to variables (reference type and otherwise) as something that they aren't and in doing so only confuse people who are trying to understand this concept.

    I know that in a strongly-typed language a variable has a type, a name, and a value or a reference to a value. At least that's what I was taught in the few introductory CS courses I have taken. But notice that I listed what a variable has, not what a variable is.

    In some contexts, the authors/lecturers often refer to a variable as a name used to represent data. In other words, if you type "int x = 1", then "x" is the variable. I think that in most cases, most of us would also think of "x" as the variable.

    But the problem I have with this definition of "variable" is that it's essentially saying that the identifier (ie: the name) used to represent the variable is in fact the variable. Some people won't dispute that definition, but in my case (and keep in mind that obviously I have a very weak computer science background) I've always known (except maybe when I was a little kid) that the name given to the thing is not the same as the thing. In other words, if your name is John, then, properly speaking, you are not John, you are just a human being whose name is John.

    By the same token, if I declare a variable of type 'int', and use the identifier/name 'x' to represent it, I still don't know what the variable is, other than the fact that it is a thing of some sort. But in some contexts, when it comes to variables, the authors/lectures make it sound like the 'thing' is the same as the name given to the 'thing'.

    In other words, such people would refer to 'x' as 'the variable'. But, unless I'm completely lost and hopeless when it comes to understanding computer science concepts, I understand that 'x' is not the variable, but the name of the variable, and the name itself is merely a sequence of characters that represent 'something' that represents a memory address that holds a sequence of zeros and ones that is interpreted as data rather than instructions.

    Assuming that I'm on the right track, am I to understand that, at least in the case of reference type variables, the type of the variable, the name given to the variable, the data stored in the memory address represented by the variable, and the representation of the memory address itself, are collectively known as 'the variable'?

    Some people will probably agree with that definition of the term 'variable' (ie: something that has a type, a name, represents a memory address that holds data or actually holds the data). But again, what a thing has and what a thing does, is not the same as what the thing is. For example, a dog has four legs, a dog has hair, a dog barks; but just because a 'thing' has 4 legs, has hair, and barks, doesn't make it a dog (before anyone says that 'bark', by definition, is a noise that a dog makes, I can tell you that at least according to the dictionaries I have consulted, 'bark' is a noise made by some animals such as foxes, wolves, and dogs).

    For the time being I accept that, at least in the case of reference type variables, a variable is 'something' that has a type, a name, and represents a memory address, irrespective of whether the memory address has data. But I still don't know what a variable is.

    Other definitions of 'variable' I've heard is that a variable is a sequence of unicode characters that the compiler transforms into a number that represents a memory address. In other words, if I type 'int myVar = 2', then the variable is the sequence of characters m-y-V-a-r whereas all those characters, collectively, are the variable's identifier. But this is akin to saying that the guy whose name is John, is J-o-h-n!

    Is a variable an abstraction?

    (The term 'abstraction' has a specific meaning in computer science, and I know that I don't entirely understand it, I only know that according to a popular online encyclopedia 'abstraction' is defined as 'the process by which data and programs are defined with a representation similar to its pictorial meaning...', so I don't feel comfortable concluding that something that I barely understand is another thing that I clearly don't understand.)

    Is a variable merely a representation of a memory address? In other words, is it an abstract concept? Is this the bottom line? If this is the bottom line then why do authors and other 'authorities' keep implying that when it comes to variables, the name of 'the thing' is 'the thing'?
    Last edited by y99q; 11-24-2011 at 11:58 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. a really stupid question
    By -EquinoX- in forum C Programming
    Replies: 33
    Last Post: 02-02-2008, 11:29 PM
  2. stupid, stupid question
    By xelitex in forum C++ Programming
    Replies: 5
    Last Post: 12-22-2004, 08:22 PM
  3. Stupid Question
    By bam34 in forum C++ Programming
    Replies: 3
    Last Post: 11-17-2004, 04:50 PM
  4. Stupid Question
    By Mornic_Programm in forum C++ Programming
    Replies: 2
    Last Post: 10-22-2004, 07:02 PM
  5. Stupid Math Question....really stupid
    By ToLazytoSignIn in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 01-16-2003, 07:36 PM