tags:

views:

137

answers:

2

I recently was quickly shortening some method names in a javascript file and ran into a problem when I converted one method name:

Before:

RefreshSevenDayGrid(){
   // some stuff
}

After:

7Day() {    
    // some stuff
}

I quickly discovered that the javascript no longer worked. I heard from several people that numbers should never be used for Method or Class names. Is there ever an exception to this?

+6  A: 

It tends to cause fits for language parsers. It sees a leading digit, so expects to begin reading a numeric literal, then barfs when it sees a letter. Even the algebraic convention is that a number to the left of a letter is a separate numeric literal with the space omitted, so 7x would be seen as two tokens.

Jeffrey Hantin
+6  A: 

Besides what Jeffrey Hantin said, there are numeric constants such as

3e7  // 3x10^7
40L  // C, C++, etc for a long integer
0x88 // hexadecimal

The general convention for identifiers which is used widely in most languages, is [S except for 0-9][S]* where S is some set of valid characters (A-Z, a-z, 0-9, sometimes _, $, or -) -- so the first character can't be a digit but the rest can.

Jason S