Coolskool : Kola Oyedeji's Cool Technology Blog

Do you use the dollar sign in variable names?

posted Sunday, 20 May 2007
Since CF 6.0 we have been able to use the $ as part of a variable name but I have yet to come across any code that actually uses it. Does anyone actually use it? Perhaps as part of some naming convention to indicate Constants for example?

tags:  

links: digg this    del.icio.us    technorati    reddit




1. Erki Esken left...
Sunday, 20 May 2007 11:31 am :: http://dreamdrummer.com/

One place where they would be useful is code generation. As replacement tokens in template code, or in special variables that you shouldn't manually change, instead change only by using code generator.

This would be then similar to JavaScript/ECMAScript (see: http://www.ecma-i nternational.org/publications/files/ECMA-ST/Ecma-262.pdf#page=26):

"The dollar sign ($) and the underscore (_) are permitted anywhere in an identifier. The dollar sign is intended for use only in mechanically generated code."


2. barry.b left...
Sunday, 20 May 2007 11:42 am

i deliberately don't. I'm old school and try to code to make it as clear and quick as possible to read. because I come from a VB background, I try make it look like pseudocode, as plain English as practically possible. In fact my favourite for this is J.D Edwards "one World" 4GL language. Perl, PHP, etc looks like crap - too cryptic. IMHO with the exception of "_" for private vars there are no naming convention needs that require "$"


3. Kola Oyedeji left...
Sunday, 20 May 2007 1:45 pm

@Erki: thats an interesting use case hadn't considered that.

@Barry: I can't think of a naming convention that would that could make good use.

One interesting point though, as you can include no other signs in ColdFusion variables this allows us to do this

$name = "some value"; name = "some other value";

Not that I think its a good idea!


4. Adam Cameron left...
Sunday, 20 May 2007 6:05 pm

Well you CAN use any character / symbol you like if you use array-notation to reference the variable:

variables = "foo";

Not that I'd recommend it, for most situations...

-- Adam


5. Adam Cameron left...
Sunday, 20 May 2007 9:29 pm

Your blog software stripped part of my posting there. Basically after the "variables" bit was square brackets containing - let's try this again - !""£#chr(7)#$%^&##. There's not much limitation in CF variable names these days.

-- Adam


6. Sean Corfield left...
Sunday, 20 May 2007 9:46 pm :: http://corfield.org/

Transfer ORM uses $ in generated code.

As Adam points out, you can use any characters in variables really since you can use bracket notation on scope names: variables = 42;


7. Sean Corfield left...
Sunday, 20 May 2007 9:47 pm :: http://corfield.org/

Sigh... as Adam noted, your blog software strips brackets...


8. Kola Oyedeji left...
Sunday, 20 May 2007 10:39 pm

@Adam/Sean: I had forgot that you could use almost anything as a variable name using that notation!


9. Dmitriy Goltseker left...
Monday, 21 May 2007 1:57 pm

I use $ sign in a special variables that I define, like logout, mpsession and resetApp. So the actual variables look like $$logout$$, $$mpsession$$ and $$resetApp$$, respectively.