All Questions
Tagged with scope programming-practices
5 questions
5
votes
1
answer
2k
views
Block Scoped and Function Scoped Languages
I've noticed that some languages like C, C++, Java, Perl, and .NET Visual Basic have "block" scoping which means that a variable will only be defined within the specific code block it was declared in.
...
1
vote
5
answers
11k
views
Is it bad form to use the same variable name in different scopes?
Say you have some basic code where similar operations will take place in nearby lexical scopes. Take for example some simple pseudo code:
variable = "foo"
# Do something with variable
if (True) {
...
43
votes
6
answers
14k
views
Should I place functions that are only used in one other function, within that function?
Specifically, I'm writing in JavaScript.
Let's say my primary function is Function A. If Function A makes several calls to Function B, but Function B is not used anywhere else, then should I just ...
4
votes
1
answer
6k
views
Where should variables be declared
Considering I have a for loop in a method of a class. Should the incremented variable be declared as member of the class, or should it be declared in the method it uses it(or even in the for loop, ...
5
votes
1
answer
482
views
Scoping recommendations while developing in C
While developing a library using C, what are your recommendations about variable and function scoping?
In C++, OOP and namespaces made the whole thing a lot easier. But how to do that with plain C? ...