Questions tagged [variable-names]

220 questions
185
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
  • 13,780
  • 18
  • 57
  • 78
145
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…
103
votes
8 answers

How can I load an object into a variable name that I specify from an R data file?

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
  • 37,328
  • 27
  • 87
  • 147
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
  • 171,942
  • 122
  • 354
  • 501
37
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
  • 10,931
  • 20
  • 65
  • 87
36
votes
1 answer

Bash variables: case sensitive or not?

Is bash shell scripting case sensitive? Is variable date the same as DATE?
Mario
  • 1,873
  • 5
  • 17
  • 21
30
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
  • 7,380
  • 8
  • 40
  • 78
29
votes
3 answers

dollar sign in variable name?

I stumbled on 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,640
  • 8
  • 25
  • 45
25
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
  • 2,147
  • 1
  • 15
  • 26
21
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
  • 5,326
  • 4
  • 41
  • 75
20
votes
2 answers

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,100
  • 1
  • 11
  • 25
19
votes
3 answers

Is there a length limit on g++ variable names?

See title​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
anon
  • 36,629
  • 47
  • 184
  • 286
17
votes
6 answers

Create variables with names from strings

Let's assume that I want to create 10 variables which would look like this: x1 = 1; x2 = 2; x3 = 3; x4 = 4; . . xi = i; This is a simplified version of what I'm intending to do. Basically I just want so save code lines by creating these variables…
Potaito
  • 1,112
  • 1
  • 10
  • 30
16
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
  • 321
  • 2
  • 6
16
votes
6 answers

What variable name do you use for file descriptors?

A pretty silly trivial question. The canonical example is f = open('filename'), but f is not very descriptive. After not looking at code in a while, you can forget whether it means "file" or "function f(x)" or "fourier transform results" or…
endolith
  • 21,410
  • 30
  • 114
  • 183
1
2 3
14 15