This is a curiosity more than anything: Does there exist a programming language that allows variables, functions, and classes to be named using using Unicode rather than ASCII (except, of course, for special characters such as '+')? Do any popular languages have support for this?
Also, related to this, if any common language supports Unicode, then is there any way to convert an existing API into a language of the user's own choice? It seems like it wo开发者_如何学Culd be helpful to give a programmer the ability to learn an API in their own language. I imagine downloading a standard API (for instance boost) and then downloading the standard translation mapping and then being able to program in my native language.
As you can see from other answers, most modern languages allow this, including Perl, Python, Go, Ruby, Java, C♯, variants of lisp, Fortess, ADA, and many more. C and C++ do not, but those aren’t modern.
Regarding C♯, from MSDN:
The rules for identifiers given in this section correspond exactly to those recommended by the Unicode Standard Annex 15
As for converting an API to a chosen language - this is not feasible. You would require a translator that understands the nuances and meaning of every method, variable and class name and translate those correctly - this is not the same as being able to use the characters of a chosen language in code.
Ada (among others) allows for internationalized identifiers using UNICODE.
However, my personal opinion is software should be written using a single, universally understandable and sufficiently simple language (English, obviously) to encourage collaboration, ensure understandability and reusability of code.
Delphi has that feature since Version 2009
Javascript has this feature.
Fortress makes extensive use of Unicode (perhaps in an APL-like way); see http://projectfortress.sun.com/Projects/Community/wiki/FeatherweightJava for one example.
.Net supports Unicode and I'm working with C# Unicode variable everyday.
C#, Java, Python3, as far as I know, are all Unicode based programming.
I found no one above mentioned Python, so I added it. Python has a fantasy feature: everything (function, class, module, variable, class instance) is object and every object can attached a document to describe it. This feature may be useful for organizing code and executing script interactively. For example:
# Python code in interactive mode
>>> def MyFunc():
'''This is self-included document.
It can be write in multi lines.'''
print('foobar')
>>> print(MyFunc.__doc__)
This is self-included document.
It can be write in multi lines.
>>> MyFunc()
foobar
Java has this feature.
Some implementations of common lisp would allow this. AFAIK the language specification doesn't forbid it or require it (it only requires a basic ASCII character set).
Tcl allows you to use Unicode characters for command and variable names, though it's recommended to avoid them for variable names because the shortcut syntax doesn't cope at the moment (i.e., you'd have to use the form [set Ω]
instead of $Ω
).
Scheme, PLT Racket and Lisp Flavored Erlang all allow for unicode identifiers (made simple thanks to prefix syntax)
Consider Swift, introduced by Apple in 2014. Here is a code snippet:
var 国 = "美国"
Good Luck with your search for the best one!
Perl and Go both allow full Unicode identifiers. Perl requires a use utf8;
declaration, but Go does this automatically.
See UAX#31: Unicode Identifier and Pattern Syntax, for various concerns.
In general, an identifier should match the pattern ^\p{ID_Start}\p{ID_Continue}*$
, although languages are free to add to that. For example, Java adds the currency symbols (\p{Sc}
), including $
.
精彩评论