14 - Static Scoping Flashcards

(14 cards)

1
Q

refers to the range of statements in which a variable is visible and can be referenced

A

scope

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

determines where a variable can be accessed or modified in a program

A

scope

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what type of scope is determined at compile-time (before execution)

A

static scope

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

static scope was introduced in which programming language?

A

ALGOL 60

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

on static scoping:

__ can access variables from their enclosing (outer) scopes unless shadowed

A

inner blocks

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

refers to when a variable with the same name is declared in a nested block which hides the outer variable

A

variable hiding and static ancestors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

on variable hiding and static ancestors:

the __ can still be accessed using a qualified name

A

outer variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

refers to a section of code that introduces a new scope for variables

A

block

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

variables declared in a block are created when __ and destroyed when __

A

the block is entered,
the block is exited

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

true or false:

block-structured languages allow local variable declarations within blocks

A

true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

true or false:

the variable inside a block disappears when the block finishes

A

true, the variable has a limited lifetime

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

__ enables clear visibility rules and is efficient to implement

A

static scoping

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

problems that are caused by having too much access to variables (3)

A
  1. procedures can access variables that they shouldn’t
  2. errors may not appear until runtime
  3. overexposure of data leads to poor encapsulation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

problems of static scoping (5)

A
  1. hard to restrict access to variables only where needed
  2. changing one part of a program may require moving entire procedures or variables
  3. moving declarations can reduce readability
  4. may lead to excessive global variables and less modular code
  5. final program design may be awkward or unintuitive due to forced structure
How well did you know this?
1
Not at all
2
3
4
5
Perfectly