There is the rule because it is ambiguous. If the variable starts with a number the compiler does not know that it is a symbol (a variable, for example). He will find it to be a numeric literal.
Notice that until now on the site when you use the number starting the name, the colorization thinks it is a literal (it is true that in these specific cases you can know that it is not a literal, but then you would have trouble identifying).
This is especially tricky when literals can have letters at the end to differentiate the type. If this did not exist in the language, it would even give the compiler a chance to figure out what it really is. It is true that this still exists, but only in certain cases. It's better not even try this. The gain would be minimal and would deal with other confusions.
Names with numbers only is not possible under any circumstances, could not differentiate.
PHP may be more permissive with some symbols since the language requires a specific character to indicate that it is a variable.
Some languages could do this with an optional escape character in this case, as it is possible to use @
in C #, for example. But again, the gain does not compensate the effort, it gives to live without variables that start with numbers. Note however that C # allows the use of @
only to escape keywords but not names beginning with numbers.
If you need a name like this because it comes from a database that accepts this type of name, it is possible in C # to use an attribute to name better, not the variable, but at least give a relationship information with column in the DB.
var 2d = 1;
WriteLine(2d); //está imprimindo "1" (o valor de 2d), ou imprimindo "2.0" que é um double)
var 3 = 1;
WriteLine(3); //está imprimindo "1" (o valor de 3), ou imprimindo "3" que é um int)
No way to know, it's ambiguous.
In your example 4teste
in thesis may not be ambiguous, but why make this exception? The gain does not pay off. And if it had this, it could limit the expansion of language.
Let's say that one day the language needs to do a literal that is determined by the teste
suffix. Okay, 4teste
would already be ambiguous. Of course, you may find that teste
is a bad suffix, but a compiler can not do value judgment. And the language could create a mechanism that the programmer creates his own suffixes and it could be teste
or something else. If there were a variable with a number and the same name, it would complicate. Example:
var 5dias = 1;
//um dia uma pessoa cria o sufixo dias, aí seria permitido:
var x = 5dias; //antes saberia que está guardando 1 em x, agora pode estar guardando 5 dias