Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Where is there a good description of the use of the word 'scope' in computer science?

In this post of a question about the Java final reserved word one responder implies that scope is textual so each iteration of a for loop causes a scope to be resumed as current. Another responder implies scope is time dependent so each iteration is a new scope. In those contexts, it was possible to understand what scope meant even though different people use the word differently but sometimes when I am reading a programming book I am not sure what scope means.

What are good qualifiers for the word 'scope'? I suggest 'textual' is one. Can you think of others? Should a qualifier almost always be used or is there a general understanding about contexts that help one perfectly infer the the intended meaning?

How is the word 'scope' used when speaking of objects (and object oriented programming) and what qualifiers might be necessary?


migration rejected from Dec 21 '15 at 12:32

This question came from our site for professional and enthusiast programmers. Votes, comments, and answers are locked due to the question being closed here, but it may be eligible for editing and reopening on the site where it originated.

closed as too broad by gnat, GlenH7, MichaelT, Scant Roger, Matthieu M. Dec 21 '15 at 12:32

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

I don't think I know any language where "textual scopes" are inconsistent with "evaluation scopes". For instance, in Java, the execution "leaves the scope" when it has to evaluate the loop condition. – zneak Jul 31 '11 at 6:21
What is the reason for the 'close it' vote, please? – H2ONaCl Jul 31 '11 at 6:26

You could consider scope in the way it's physically implemented at the machine level. Pushing and popping from a stack. Once you're popped off the stack, you no longer exist (out of scope).


For a variable to be "in scope" at a given location mean that you can write a snippet of code at that location that reference the value held by that variable.

This is not specific to objects but to the rules of the language.

How a variable should be treated before it is allowed to go out of scope varies depending on the language.

  • C require that memory allocated and stored in a pointer is returned to the memory pool before the pointer falls out of scope.
  • Java allows object references to fall out of scope and automatically be returned to the memory pool. If the object held resources needing explicitly to be free, this should be coded manually before the object falls out of scope.
  • Objective-C require the programmer to manually keep track of the number of uses for a given object, and when the object counter is zero the object is released.

So, scope just indicates "visibility" - where is the variable usable?


Not the answer you're looking for? Browse other questions tagged or ask your own question.