A scope is a defined context inside which certain defined entities of a programming language are visible – and outside which it is NOT visible. Various programming languages have different scope rules – of which particular interest is static and dynamic scoping.
In static scoping, the scope of the identifier is determined at compile time itself. A static scoped language resolves the identifier to a declaration at compile time using the scope rules. An example of statically scoped language is C, where every identifier is resolved to either a fixed address or to an offset inside the activation record during compilation. Since every identifier is uniquely bound to an address and scoping is determined, there is no runtime overhead in computing the scope of identifiers.
In dynamic scoping, the scope of the identifier is known only at runtime. In this case, the identifiers that are to be accessed by a procedure will be known only after it is invoked. Depending from where it was invoked, the procedure may have access to different identifiers. This means that the scope of the identifier is determined by the call sequence at runtime, which the compiler cannot determine. Since the scoping needs to be computed during runtime, runtime overhead exists to resolve the value of an identifier when encountered during execution.
Static scope is considered better because the scoping will be clear in the program code itself. This results in very readable programs. Dynamic scoped programs are difficult to read and maintain, since determining the scope and values of identifiers by analyzing the program code will be confusing for the programmer.
good explanation
very well explained. thanks.:cool:
not upto the mark
the explaination is nice bt some ex shud also b included!!!