Why is it bad to start a variable name with a doll

2019-05-10 17:43发布

Why is it bad to start a variable name with a dollar sign in C++/Java and similar such as in PHP?

Edit: Are there any risks?

8条回答
smile是对你的礼貌
2楼-- · 2019-05-10 18:44

Java allows the dollar sign to begin identifiers, but recommends that it only be used for mechanically generated code. (see here)

It appears that in C++ identifiers may be able to use dollar signs as an extension, but it's not part of the standard.

查看更多
男人必须洒脱
3楼-- · 2019-05-10 18:47

Because in both C++ and Java doing so would be a syntax error (in the case of C++) or bad style (in the case of Java). Neither of these languages need variables to be so indicated, and doing so is wrong. Starting variables with a special character (like '$') makes things a lot easier for the language system (which is important for interpreted languages like PHP), but makes life much harder for the programmer, because they have to type in all those '$' characters. So most languages (even most interpreted languages) don't require them.

查看更多
登录 后发表回答