[Tutor] Question about 'scopes'

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Mon Mar 24 14:57:01 2003


On Mon, 24 Mar 2003, ahimsa wrote:

> Anyway, aside from being verbose, I am also curious as to whether the CS
> concept of 'scope' can be compared with the biological or cybernetic
> concepts of 'system', or 'domain of reference', in that a scope
> 'encloses' a particular set of attributes and methods much as a system
> can be said to 'contain' parts.

Scope can be thought of as containment.  For example, the biological
analogy to scope might be to a cell and its membrane.


Let's abuse the analogy.  Variable names that are local to a function are
like enzymes in a cell:  the cell membrane localizes the effect of enzymes
so that they don't do random things to the whole system, but only within
the context of the cell.  Likewise, the scope of a function limits the
effects of variable names so that we don't effect change globally
throughout the system.


Some cells do allow controlled input and output through membrane channels,
and these channels allow material to flow in and out of the cell in a
controlled way.  In computer languages, the concept of a return value and
input parameters allows us to control the flow of information in and out
of a particular function.


So it's possible to borrow many of the terms of biology and apply them
inappropriately to programming.  *grin*


Hope this helps!