Variable or scalar is a storage location paired with an associated symbolic name (an identifier), which contains some known or unknown quantity or information referred to as a value.
Questions tagged [variables]
204 questions
184
votes
10 answers
Why is Clean Code suggesting avoiding protected variables?
Clean Code suggests avoiding protected variables in the "Vertical Distance" section of the "Formatting" chapter:
Concepts that are closely related should be kept vertically close to each other. Clearly this rule doesn't work for concepts that…

Matsemann
- 1,918
- 3
- 16
- 21
161
votes
6 answers
Should the variable be named Id or ID?
This is a bit pedantic, but I've seen some people use Id as in:
private int userId;
public int getUserId();
and others use:
private int userID;
public int getUserID();
Is one of these a better name than the other? Why? I've seen this done very…

Adam
- 2,141
- 2
- 16
- 15
118
votes
2 answers
What does the term "Payload" mean in programming
I was going through the source code of an open source framework, where I saw a variable "payload" mentioned many times. Any ideas what "payload" stands for?

Vishwas
- 1,871
- 4
- 15
- 15
103
votes
13 answers
Should we eliminate local variables if we can?
For example, to keep a CPU on in Android, I can use code like this:
PowerManager powerManager = (PowerManager)getSystemService(POWER_SERVICE);
WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,…

ggrr
- 5,725
- 11
- 35
- 37
79
votes
3 answers
"state" or "status"? When should a variable name contain the word "state", and when should a variable name instead contain the word "status"?
Reading code and discussions pertaining to code, I often see the words "state" and "status" used interchangeably, but the following tendencies seem to exist:
When a variable holds a value intended to indicate that something is in a certain state,…

Will
- 901
- 1
- 6
- 7
63
votes
8 answers
Prefer class members or passing arguments between internal methods?
Suppose within the private portion of a class there is a value which is utilized by multiple private methods. Do people prefer having this defined as a member variable for the class or passing it as an argument to each of the methods - and why?
On…

geoffjentry
- 870
- 1
- 6
- 8
62
votes
12 answers
Should I reuse variables?
Should I reuse variables?
I know that many best practices say you should not do it, however, later, when different developer is debugging the code and have 3 variables that look alike and the only difference is that they are created in different…

IAdapter
- 1,345
- 1
- 9
- 22
60
votes
14 answers
What is the history of the use of "foo" and "bar" in source code examples?
Why do many code examples, especially tutorials, use the names "Foo" and "Bar" so often? It is almost a standard.
For example:
void foo(char* bar) {
printf("%s", bar);
}
user15453
53
votes
15 answers
Clean Code: Functions with few parameters
I read the first chapters of Clean Code by Robert C. Martin, and it seems to me it's pretty good, but I have a doubt, in one part it is mentioned that it is good (cognitively) that the functions should have as few parameters as possible, it even…

OiciTrap
- 729
- 1
- 7
- 12
53
votes
15 answers
Is it bad practice to name an unused variable with a single underscore?
Often when the syntax of the language requires me to name a variable that is never used, I'll name it _.
In my mind, this reduces clutter and lets me focus on the meaningful variables in the code. I find it to be unobtrusive so that it produces an…

Kris Harper
- 2,237
- 2
- 19
- 21
52
votes
9 answers
How to name a variable when the word is both a noun and a verb
I have run into a corner-case problem with the general guidance of:
nouns for variables
verbs for functions
Specifically, I have a case where the word is ambiguous - it can be either a verb or a noun. And in some cases when we're discussing the…
user53019
50
votes
17 answers
Is it a good practice to name the returned variable "result"?
Is it a good practice to call the variable a method returns with a variable name result?
For instance:
public Zorglub calculate() {
Zorglub result = [...]
[...]
return result;
}
Or should I name it by its type?
public Zorglub…

Nicolas Raoul
- 1,062
- 1
- 11
- 20
49
votes
12 answers
Intentional misspellings to avoid reserved words
I often see code that include intentional misspellings of common words that for better or worse have become reserved words:
klass or clazz for class: Class clazz = ThisClass.class
kount for count in SQL: count(*) AS kount
Personally I find this…

Nicole
- 28,111
- 12
- 95
- 143
45
votes
5 answers
How do variables in C++ store their type?
If I define a variable of a certain type (which, as far as I know, just allocates data for the content of the variable), how does it keep track of which type of variable it is?

Finn McClusky
- 527
- 1
- 4
- 5
45
votes
4 answers
Why do so few languages with a variable-type 'operator' exist?
I mean it in this way:

kgongonowdoe
- 541
- 4
- 7