Tagged Questions
4
votes
3answers
2k views
What is meant by Scope of a variable?
I think of the scope of a variable as -
"The scope of a particular variable is the range within a program's source code in which that variable is recognized by the compiler".
That statement is ...
4
votes
2answers
171 views
How to deal with variables when extracting methods in to smaller methods?
This is an abstract question to clarify a refactoring concept in the ruby language. Assume in the real world that there would be many more variables and method in the Furniture Class and Refinish ...
5
votes
6answers
468 views
Is it OK to use dynamic typing to reduce the amount of variables in scope?
Often, when I am initializing something I have to use a temporary variable, for example:
file_str = "path/to/file"
file_file = open(file)
or
regexp_parts = ['foo', 'bar']
regexp = new ...
5
votes
4answers
743 views
When would dynamic scoping be useful?
With dynamic scoping, a callee can access the variables of its caller. Pseudo C code:
void foo()
{
print(x);
}
void bar()
{
int x = 42;
foo();
}
Since I have never programmed in a ...