Alphanumeric identifiers and the $ character

From programming in the Scala section of section 6.10 (Page 151):

Identifiers in user programs should not contain the '$' character, although it will compile; if they do, this could lead to name conflicts with identifiers generated by the Scala compiler.

I'm sure this is the reason for this, but why not prevent the use of the '$' character in alphanumeric identifiers?

+4
source share
1 answer

Some identifiers generated internally by the Scala compiler contain the characters '$'. If you create new identifiers with $$ characters, you may encounter internally generated characters and chaos sets in. OTOH, you sometimes need the "$" characters, either on those (very rare) occasions when you need access to the internally generated Scala characters, or because someone used that identifier in the Java code that you want to call (where it's legal if also not recommended).

+8
source

Source: https://habr.com/ru/post/1390853/


All Articles