Questions tagged [scoping]

For questions about scopes within a program in which variables are available.

Filter by
Sorted by
Tagged with
8 votes
4 answers
2k views

Why are mixed declarations more challenging to implement than forcing all declarations to be at the top of a scope?

C89 had a requirement that all declarations must appear at the top of the scope before any statements: ...
user16217248's user avatar
  • 7,535
11 votes
4 answers
991 views

Data structures for scopes and variable shadowing

Let's say I have some code in my target language like: ...
Rob N's user avatar
  • 1,073
7 votes
2 answers
1k views

Dynamic and Static scoping and recursion

So I learned the concept of lexical and dynamic scoping in programming languages. But I am not quite sure about the behaviour of these concepts in recursion(or even not recursion, but two different ...
poiug07's user avatar
  • 73
13 votes
7 answers
2k views

Pros and cons of automatically importing the scope of the object in the methods

In C++, you could refer to members of a class directly in its member functions. Many other languages requires an explicit this. or ...
user23013's user avatar
  • 2,240
7 votes
2 answers
304 views

How to implement dynamic scoping?

How to implement dynamic scoping? Dynamic scoping is useful for forms of dependency injection, error handling and alternatives to thread local storage. Some examples of dynamic scoping include React's ...
Molly Stewart-Gallus's user avatar
6 votes
2 answers
257 views

What are the advantages of conditional statements having their own scope?

What are the advantages of conditionals having their own scope? I know this can lead to some extra variables for some programs. But it can also be more memory efficient. Credit to Hg0428 for the idea ...
Ethan's user avatar
  • 377
17 votes
3 answers
863 views

What are the pros and cons of allowing variable shadowing in the general case?

In many languages, variable shadowing is restricted to various degrees, or not at all. To me, unrestricted variable shadowing seems like a classic "footgun" in that, while a savvy programmer ...
Unrelated String's user avatar
8 votes
3 answers
219 views

What are some approaches to namespacing?

Objective-C didn't have namespaces, so everyone chose a two- or three-letter prefix to stick on everything. This has effects to this day as typenames like NSObject ...
Bbrk24's user avatar
  • 8,857
9 votes
7 answers
416 views

What are the pros and cons of dynamic scoping?

In dynamic scoping, if a function accesses a variable in a higher scope, it does so relative to the location it's called rather than the location it's defined. For example: ...
Rydwolf Programs's user avatar
23 votes
5 answers
811 views

What options in Unicode are there for balanced pairs of brackets like `(){}[]<>`?

My esolang involves the use of balanced brackets (){}[]<> to denote different scopes. However, unlike practical languages, all pairs of identical brackets ...
bigyihsuan's user avatar
  • 1,663