Questions tagged [variable-names]
256 questions
223
votes
10 answers
A table name as a variable
I am trying to execute this query:
declare @tablename varchar(50)
set @tablename = 'test'
select * from @tablename
This produces the following error:
Msg 1087, Level 16, State 1, Line 5
Must declare the table variable "@tablename".
What's the…

SoftwareGeek
- 15,234
- 19
- 61
- 78
163
votes
24 answers
Why can't variable names start with numbers?
I was working with a new C++ developer a while back when he asked the question: "Why can't variable names start with numbers?"
I couldn't come up with an answer except that some numbers can have text in them (123456L, 123456U) and that wouldn't be…

Jeremiah
- 5,386
- 9
- 38
- 45
118
votes
9 answers
Can I load a saved R object into a new object name?
When you save a variable in an R data file using save, it is saved under whatever name it had in the session that saved it. When I later go to load it from another session, it is loaded with the same name, which the loading script cannot possibly…

Ryan C. Thompson
- 40,856
- 28
- 97
- 159
95
votes
33 answers
Am I immoral for using a variable name that differs from its type only by case?
For instance, take this piece of code:
var person = new Person();
or for you Pythonistas:
person = Person()
I'm told constantly how bad this is, but have yet to see an example of the immorality of these two lines of code. To me, person is a…

Jason Baker
- 192,085
- 135
- 376
- 510
53
votes
1 answer
Bash variables: case sensitive or not?
Is Bash shell scripting case sensitive?
Is variable date the same as DATE?

Mario
- 2,303
- 5
- 20
- 21
42
votes
10 answers
Programmatic way to get variable name in C?
I am developing a tool to dump data from variables.
I need to dump the variable name, and also the values.
My solution: Store variable name as a string, and print the "variable name", followed by its value.
Is there any programmatic way to know the…

Alphaneo
- 12,079
- 22
- 71
- 89
35
votes
4 answers
Dollar sign in variable name
I stumble upon some C++ code like this:
int $T$S;
First I thought that it was some sort of PHP code or something wrongly pasted in there, but it compiles and runs nicely (on MSVC 2008).
What kind of characters are valid for variables in C++ and are…

Valmond
- 2,897
- 8
- 29
- 49
33
votes
2 answers
Can variable names in Python start with an integer?
This is somewhat academic, but nevertheless.
Python syntax forbids starting a variable name with a number, but this can be sidestepped like so:
>>> globals()['1a'] = 1
>>> globals()['1a']
1
Likewise for locals().
Does that mean that Python actually…

steffen
- 8,572
- 11
- 52
- 90
27
votes
1 answer
Why can I declare a child variable with the same name as a variable in the parent scope?
I wrote some code recently where I unintentionally reused a variable name as a parameter of an action declared within a function that already has a variable of the same name. For example:
var x = 1;
Action myAction = (x) => {…

stellr42
- 3,365
- 2
- 21
- 33
26
votes
6 answers
Is _ (single underscore) a valid C++ variable name?
With gcc 4.7.2 this compiles just fine for me:
int main()
{
int _ = 1;
return 0;
}
Can I expect this to compile in general? I've read the answers about underscores as prefixes. But what if the underscore isn't prefixing anything?

Alec Jacobson
- 6,032
- 5
- 51
- 88
21
votes
3 answers
How to get the name of a variable in Kotlin?
I have a Kotlin class in my application with a lot of attributes, what I want to build is a method that stores the variable name in a dictionary. The dictionary looks like this:
HashMap>()
The purpose of this is to store the…

SparklyUnicorn
- 1
- 2
- 5
- 18
21
votes
1 answer
PHP: Variable function name (function pointer) called ; How to tell IDE my function is called?
I'm currently trying to remove all errors and warnings I have in my project the Inspection tool from my PHPStorm give to me.
I encounter a snippet PHPStorm says "Unused private method _xxx" while it's actually used, but in a dynamical way. Here is a…

niconoe
- 1,191
- 1
- 11
- 25
20
votes
2 answers
How does one use a variable name with the same name as a package in Go?
A common variable name for files or directories is "path". Unfortunately that is also the name of a package in Go. Besides, changing path as a argument name in DoIt, how do I get this code to compile?
package main
import (
"path"
…

Nate
- 5,237
- 7
- 42
- 52
20
votes
4 answers
Variable name percent from 0 to 1
So this seems like I should have been wondering about this when I first started programming, but I suppose back then I wasn't as concerned with 'perfect' variable naming.
So I have the variables
float lifeTime;
float age;
Where lifeTime is the full…

user3294236
- 380
- 2
- 7
20
votes
3 answers
Is there a length limit on g++ variable names?
See title

anon
- 41,035
- 53
- 197
- 293