Main Page | See live article | Alphabetical index

Scope

The scope of a given activity or subject is the area or range of what it covers.

In computer programming, the scope of an identifier refers to where and when in the program the identifier can be referenced. Scope applies to all identifiers in a program, but it is mostly used for variables, functionss and classeses.

For example, the scope of a variable refers to where in the program the variable can be accessed and/or modified. For a function, to where the function can be called, and so on.

Common scope levels:

Scope is usually hierarchical: a variable declared at local scope (for example, as a local variable inside a function) supersedes the same variable declared at global scope. All references to this variable inside the function will manipulate the locally-defined variable. Outside the function, they will manipulate the globally-defined variable.

Because of this automatic scope handling, careful magamenent of variable, class and function names should be a requirement for any non-trivial program. It is considered good programming practice to make variables as narrow a scope as feasible so that different parts of your program do not accidentally interact with each other by modifying each other's variables. Common techniques for doing so are to have different sections of your program use different namespaces, or else make individual variables private through either dynamic variable scoping or lexical variable scoping.

In project management, scope refers to the sum total of all project products and their features. See also scope creep.


Also the term used in firearms for a telescopic sight.