Oct
08
2017

Session II : Names, Binding, Scope

Session II : Names, Binding, Scope

In this Session II : Names, Binding, and Scope, there are 4 sub topics :

  • Introduction
  • Names
  • Variables
  • The Concept of Binding
  • Scope

Introduction

Imperative programming languages are, to varying degrees, abstractions of
the underlying von Neumann computer architecture. The architecture’s two
primary components are its memory, which stores both instructions and data,
and its processor, which provides operations for modifying the contents of the
memory.

A variable can be characterized by a collection of properties, or attributes,
the most important of which is type, a fundamental concept in programming
languages. Designing the data types of a language requires that a variety of
issues be considered. Among the most important of these issues are the scope and lifetime of variables.

Names

A name is a string of characters used to identify some entity in a program. For every programming language, they have maximum length for the names. Fortran 95, in their programming language, can only contain names with maximum length of 31. C99: no limit but only the first 63 are significant. And for C#, Java, C++ have no limit for their name’s length.

And for some other programs, they need special character for the names. For example : PHP, all variable names must begin with dollar signs($) ; Perl,all variable names begin with special characters, which specify the variable’s type; and Ruby, for variable names that begin with @ are instance variables and for those that begin with @@ are class variables. And also there are some programs that are case sensitive such as C, C#, and Java

For notes : if the names are too short, they cannot be connotative by others. So it’s recommended to have longer length for the names ( or as clear as possible for the names so it can be read by others )

Variables

Variable is an abstraction of a computer memory cell or collection of cells.

The move from machine languages to assembly languages was largely one
of replacing absolute numeric memory addresses for data with names, making
programs far more readable and therefore easier to write and maintain. That
step also provided an escape from the problem of manual absolute addressing,
because the translator that converted the names to actual addresses also chose
those addresses.
A variable can be characterized as a sextuple of attributes: name, address,
value, type, lifetime, and scope.

The Concept of Binding

A binding is an association between an attribute and an entity, such as
between a variable and its type or value, or between an operation and a symbol.
The time at which a binding takes place is called binding time.

Binding can be divided into two : Static and Dynamic. A binding is static if it first occurs before run time begins and remains unchanged throughout program execution. If the binding first occurs during run time or can change in the course of program execution, it is called dynamic. However, this processes are maintained by computer hardware, and the changes are invisible to the program and the user. Static and Dynamic type of binding have their own advantage and disadvantage. For the static type of binding, it’s efficient but lacks of flexibility. And for the dynamic type of binding, it’s really flexible but hard to be checked if there’s something wrong or missing and has high cost.

Back to the variable sub-topic, variables’ attributes : storage bindings and lifetime. Storage bindings of the variables can be divided into two : allocation and deallocation. Allocation is a process that the memory cell to which a variable is bound somehow must be taken from a pool of available memory. And deallocation is the process of placing a memory cell that has been unbound from a variable back into the pool of available memory. The lifetime of a variable is the time during which the variable is bound to a specific memory location. So, the lifetime of a variable begins when it is bound to a specific cell and ends when it is unbound from that cell.

The lifetime of variables itself has 4 categories :

  • Static  : bound to memory cells before execution begins and remains bound to the same memory cell throughout execution
  • Stack-dynamic  : Storage bindings are created for variables when their declaration statements are elaborated.
  • Explicit heap-dynamic  : Allocated and deallocated by explicit directives, specified by the programmer, which take effect during execution
  • Implicit heap-dynamic  : Allocation and deallocation caused by assignment statements

Scope

Scope is also one of the variables’ attributes. The scope of a variable is the range of statements in which the variable is visible. The scope of a variable can also be divided into 3 categories : Local variables, those that are declared in that unit;  The nonlocal variables, those that are visible in the unit but not declared there; and global variables, that are a special category of nonlocal variables. Scope itself can be divided into Static and Dynamic Scope. Static scope refers to scope of a variable is defined at compile time itself that is when the code is compiled a variable to bounded to some block scope if it is local, can be bounded to entire Main block if it is global. Dynamic scope refers to scope of a variable is defined at run time rather than at compile time.

 

End of the Session II : Names, Binding, and Scope

Written by stevenbudinata in: Tugas Programming Language Concept |

No Comments »

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress. Kredit, Streaming Audio | Theme by TheBuckmaker.