Questions tagged [scoping]
For questions about scopes within a program in which variables are available.
10 questions
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:
...
11
votes
4
answers
1k
views
Data structures for scopes and variable shadowing
Let's say I have some code in my target language like:
...
7
votes
2
answers
2k
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 ...
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 ...
7
votes
2
answers
702
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 ...
6
votes
2
answers
422
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 ...
18
votes
3
answers
2k
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 ...
9
votes
3
answers
368
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 ...
9
votes
7
answers
1k
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:
...
24
votes
5
answers
2k
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 ...