Skip to main content

Questions tagged [local-variable]

A variable whose scope is contained to a smaller unit of code such as a function or class.

0 votes
5 answers
366 views

When, if ever, should a private member variable, used in one function, be made into a local static variable?

Lately, I have been playing with this idiom: Changing a private member variable into a local static variable when: member to singleton class used in only one function member is mutex for a shared ...
Anon's user avatar
  • 3,633
1 vote
2 answers
300 views

Scheme's define in Common Lisp

In Common Lisp, we have to use the let form to declare a new lexically-scoped variable. This means that the code either looks like that written in C89 (all variables declared on top of scope), or ...
ndsrib's user avatar
  • 19
0 votes
2 answers
315 views

Symbolic constants versus variables

coders. I'm learning C programming language and found out such thing as #define directive that allows us to use symbolic constants (following Brain Kernigan). I know that this directives "insert&...
CoderDesu's user avatar
  • 1,015
0 votes
2 answers
1k views

Reassign parameter to local variable

On Stack Overflow I frequently see questions with code in the following style: function funcName(parameter) { let variable = parameter; // rest of function uses variable rather than parameter } ...
Barmar's user avatar
  • 346
2 votes
4 answers
2k views

Is a class with a high number of member variables bad and is there a design structure for data processing?

Context: Java, fairly new developer I have inherited code from a friend for a project that processes variables. The first thing i notice is the class has a ton of member variables. I have always been ...
Ian's user avatar
  • 137
37 votes
8 answers
10k views

Does "variables should live in the smallest scope as possible" include the case "variables should not exist if possible"?

According to the accepted answer on "Rationale to prefer local variables over instance variables?", variables should live in the smallest scope possible. Simplify the problem into my interpretation, ...
ocomfd's user avatar
  • 5,750
-2 votes
2 answers
313 views

Is there any consequences to write for(float i=0, myFloatVar=0; i < n; i++)?

For example, sometimes I need a float variable to be used inside a for loop, e.g.: float sum=0; for(int i = 0; i < students.length; i++) { sum += Math.random(); students[i].result = sum; } ...
ocomfd's user avatar
  • 5,750