Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alphanumeric identifiers and '$' character

Tags:

scala

From Programming in Scala section 6.10 (Page 151):

Identifiers in user programs should not contain '$' character, even though it will compile; if they do this might lead to name clashes with identifiers generated by Scala compiler.

I am sure it's a reason for this, but why not prevent use of the '$' character in alphanumeric identifiers?

like image 402
PrimosK Avatar asked Feb 21 '23 20:02

PrimosK


1 Answers

Some of the identifiers generated internally by the Scala compiler contain '$' characters. If you create new identifiers with '$' characters, you might clash with the internally generated characters, and chaos ensues. OTOH, you sometimes need to '$' characters, either on those (now very rare) occasions when access to the internally generated Scala characters is necessary, or because someone used such an identifier in Java code you wish to call (where it's legal, if also discouraged).

like image 71
Dave Griffith Avatar answered Mar 04 '23 23:03

Dave Griffith