[Proposal] Support emoji for variable name 🍍🐶🐮🚀 #3490
Replies: 59 comments 12 replies
-
see #1742 (comment) However, 🍍 can not be an identifier because its category is Other Symbol. |
Beta Was this translation helpful? Give feedback.
-
Ah what a disappointment :( closing as dup then. |
Beta Was this translation helpful? Give feedback.
-
Reopening as this is a different request on valid unicode for variable name. This has been implemented in g++ 10. Fixing issue https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67224 g++ 10.1.1 + binutils 2.34.0.20200522) |
Beta Was this translation helpful? Give feedback.
-
I, for one, would gladly welcome any language changes that would include more 🥓. Swift is another language that allows for characters such as emoji in identifiers: let 🐶🐮 = "dogcow"
let #🚀 = "Hashrocket"
NSLog(#🚀) |
Beta Was this translation helpful? Give feedback.
-
Note that the C# spec (mostly) attempts to follow Unicode Standard Annex #31: Unicode Identifier and Pattern Syntax, which does not allow emoji. |
Beta Was this translation helpful? Give feedback.
-
Thank heavens for that! Emojis in strings are all fine (I still hate them, but that is completely beside the point), however, imagine trying tracking down a bug for hours on end only because your field named :santaclaus: has the wrong gender or skin colour. IMO, C# code (meaning symbol names - not string literals) should be restricted to UTF-16. |
Beta Was this translation helpful? Give feedback.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
What exactly do you want to use as identifiers? spec needed. FYI:
|
Beta Was this translation helpful? Give feedback.
-
FWIW C++ supports them: https://godbolt.org/z/P37427 The list of allowed characters in the standard seems to allows ZWJ as well |
Beta Was this translation helpful? Give feedback.
-
i would champion an effort to get C# to support any/all identifiers that match the unicode identifier annex. If emojis are part of that annex, then that would naturally fall out. If they are not, i wouldn't support or do work to make them part of the language for identifiers. |
Beta Was this translation helpful? Give feedback.
-
Emoji is not. Most of Emoji are Other Symbol. |
Beta Was this translation helpful? Give feedback.
-
Good to know. Not championing this issue then. Thanks! |
Beta Was this translation helpful? Give feedback.
-
Apparently Clang 10 support it. |
Beta Was this translation helpful? Give feedback.
-
@ufcpp I think the same as C++ would be perfect. http://eel.is/c++draft/lex.name#1 |
Beta Was this translation helpful? Give feedback.
-
I admit this was initially for fun, but the discussion is actually interesting. |
Beta Was this translation helpful? Give feedback.
-
I don't know what you mean by this. UTF-16 can encode emoji, or else C# strings wouldn't be able to hold them. UTF-16 uses a single 16-bit number for BMP characters, and two 16-bit numbers for characters outside the BMP. If you mean that you think identifiers should be restricted to the BMP, then I strongly disagree. The BMP/non-BMP distinction is purely historical and has nothing to do with suitability for identifiers or how “wacky” a character is. There are multiple living languages that are written in characters partially or entirely outside of the BMP. As for whether emoji should be allowed in variable names, I think the Unicode recommendations for identifiers are very sound. There's a reason that $ isn't allowed in identifiers, and emoji fall into a similar logical category. The Unicode recommendations are very logical and consistent. For example, they consider numbers in other numeral systems to work along the same logical principles as the Arabic numerals 0 through 9 when it comes to where they can occur in identifiers. I wouldn't agree with further deviating from a standard which has had a lot of effort and thought put into it. |
Beta Was this translation helpful? Give feedback.
-
Where is the reasoning? |
Beta Was this translation helpful? Give feedback.
-
The way I see it, the reasoning is this: languages usually don't allow “symbols” in identifiers because they usually use them as part of the syntax of the language instead. Think of all the operators in C# for example. So within ASCII or EBCDIC or whatever old encoding with a small set of characters, generally programming languages allow the set of characters which can be used to write words to be used in identifiers, and reserve other characters for use by language syntax without the need for whitespace delineation. Often numbers are considered okay, as long as they're not at the start of an identifier so there's no confusion with literals. Now, when we move beyond these old encodings into Unicode, what do we do? The approach that the standard that C# follows takes is essentially just to extend that pattern out, and try to be as consistent as possible. Characters which are used to write words are allowed, just as before. Characters which are used as symbols, punctuation, whitespace, or control are not. Characters which are used only in the writing of numbers in other (human) languages are allowed, but not at the beginning of an identifier. It has a logical consistency to it that you lose if you just say: “This character is really cute, therefore I want to name a class with it.” If you want fun names, options are still open without emoji. You can name your variables in Ancient Egyptian written in hieroglyphs if you want. Or at least you will be able to once the issues around non-BMP identifiers are fixed in Roslyn. |
Beta Was this translation helpful? Give feedback.
-
Personally I don't care for this. I'm not against it being in the language if it were somehow "free" in terms of cost to get it to work, although I would certainly ban any use of emoji in any code base my team works on. But it's not free to get it to work, I think the team's time can be spend on much more valuable additions. |
Beta Was this translation helpful? Give feedback.
-
I second that! |
Beta Was this translation helpful? Give feedback.
-
Even if free, I would reject this proposal. So far I haven't seen any compelling cases where this would be valuable or appropriate, and I've seen a lot of cases that show why I would not want this in the language. |
Beta Was this translation helpful? Give feedback.
-
That's something already possible today with variable name suffixed by an automatic increment, something like Side note: I didn't find any color variation for the 🍣 sushi emoji, but it would be a nice thing for Intellisense to check for emoji |
Beta Was this translation helpful? Give feedback.
-
"Well, C++ did it" is generally a pretty good argument in favor of not doing something, particularly when the majority of other languages are not doing the same thing. A lot of the success of the CLR and the C# language is built on learning from C++'s mistakes rather than repeating them. |
Beta Was this translation helpful? Give feedback.
-
Interesting idea but certainly no. Please think about people who are visually impaired. Explicit and long names are always better. |
Beta Was this translation helpful? Give feedback.
-
I support this request because I think it would add a lot of value when trying to teach the langue to beginners, or even as a fun way to introduce new features to existing developers. It's not necessarily a good practice for production code, but not all code is production code. Expressiveness is an important feature of a language, and Emoji are a powerful way of expressing certain idea's. |
Beta Was this translation helpful? Give feedback.
-
If this gets implemented, it would have to be paired with an analyzer and a rule to disallow emojis (preferably disallowed by default). Given those conditions, I think it's not a bad idea, but at that point the implementation cost probably skyrockets (someone with an understanding of implementing Roslyn analyzers could determine exactly how costly it would be). |
Beta Was this translation helpful? Give feedback.
-
I want this exclusively so I can do throw new 🤷♂️(); |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
C++ isn't the only language that supports emoji identifiers. You can also do it in Ruby.
|
Beta Was this translation helpful? Give feedback.
-
To my disappointment, variable names does not support all unicode characters
How to reproduce
Expected
The code build and I can use fruits to better communicate code requirements via variable names.
Actual
A build error
I am using C# 8.0.
Beta Was this translation helpful? Give feedback.
All reactions