Home » Programming » 03 - Names, Bindings and Type Checking
3

Binding, Names, Variables, and Constants

When a program is being made, certain elements of the program are bound to certain characteristics.

Binding

When a program is being made, certain elements of the program are bound to certain characteristics. For example, in an equation y = x + 4, you can bind the values of x to be integers only. Consequentially, y will always be an integer too. The act of fixating the possible values of x to integers is an example of binding. The act of entering a value for x is also an act of binding. Why should certain variables be bound anyway? This depends on the scenario at hand. In the aforementioned equation, if y and x represent a certain amount of people then you should not have one and a half person, right? Binding allows programs to make sense when it matters. Binding can be done during execution time, translation time, language implementation time, or during language definition time. When a program is being executed, variables are normally bound to their values and to their particular storage locations in the memory. When a program is being translated, variables are usually bound to particular data types, are given names, and assigned to certain structures. When a program is being implemented, binding happens when the program has interface with the hardware. When a program is being defined, binding is already fixed upon creation of the programming language. Any alteration to the programming language itself will change the binding of a said program.

Names, Variables, and Constants

Names, variables, and constants in programs work like names and variables in real life. You give a name to a variable, a label, a program, or whatever you want to name. Names are basically a string of characters that are used to identify some element of a program. Names in a program can have many characteristics like being case sensitive or having a limited amount of characters. Names can not take on any predefined value in a programming language. For instance, in Visual Basic, you can not name your variable “global” because the Visual Basic programming language has already defined it to do something. Variables are elements in a program that vary from one value to another. For example, the variable x can take on the value of 11 or 24. Constants, on the other hand, are elements in a program that have a specific value during its lifetime. For example, the constant x can be said to be fixed at 14.

Variables can be classified by the way they are stored. Each type of variable has its own pros and cons when being used in a program. A static variable is a variable that can only be accessed within the function where it was declared. For example, if you declare the variable x within your first function then you can only access that variable within that function. When you go to the second function, you will not be able to access the said variable, variable x, anymore. The value of a static variable is preserved upon exit of the function and can still be accessed when using the function again. This means that when you exit the function and enter the function again, you will still be able to access the variable that you declared previsouly. If you exit your first function and then go to the second function then if ever you decide to return to the first function, variable x can still be used. Dynamic variables are bascially variables that can be declared anywhere. They are not limited within a function or subprogram. Stack dynamic variables are variables that are declared right when the program is run. Right when you start the program, you can declare variables that can be used on all functions and subprograms. Explicit heap dynamic variables are variables that are explicitly stated by the programmer during run time. While a program is running, a programmer can choose to declare a variable right there and then. Implicit heap dynamic variables are variables that can be used any time they are assigned. These variables are usually pre declared within the programming language. The programmer can basically use these variables anytime he or she wants to.

Variables can be classified based on where they are declared. Local variables are variables that are declared within a function. The declarations cease when one exits the function. Non local variables are variables that are not merely restricted within a function. They can be global or external. Global variables are declared outside functions and are available to all functions within a file. External variables are basically global variables that are applicable across several files.

Why don't you try making some variables in your Visual Basic editor? For the meantime, name your variable and classify it as an integer. You can do this by typing in Dim YourVariable As Integer . Use your variable to display text like you did in the Hello World example.