Why does Java allow control characters in its identifiers?

后端 未结 3 931
梦如初夏
梦如初夏 2020-12-23 17:44

The Mystery

In exploring precisely which characters were permitted in Java identifiers, I have stumbled upon something so extremely curious that it seems nearly ce

3条回答
  •  醉酒成梦
    2020-12-23 18:03

    Another question might be: Why shouldn't Java allow control characters in its identifiers?

    A good principle when designing a language or other system, is to not forbid anything without good cause, since you never know how it might be used, and the less rules implementers and users have to contend with, the better.

    It is true that you certainly shouldn't take advantage of this, by actually embedding escapes into your variable names, and you won't see any popular libraries that expose classes with null characters in them.

    Certainly, this could be abused, but it isn't the language designers job to protect programmers from themselves in this way, any more than by forcing proper indentation or well-chosen variable names.

提交回复
热议问题