By allowing Unicode characters in constant and variable names, Apple’s new Swift programming language will allow programmers whose native languages don’t use the Roman alphabet to write code that makes more sense to them. Since emoji are part of the Unicode set, expect to see amusing code demos and search-and-replace pranks that look like this:
(And yes, this code compiles and runs on Swift using the XCode 6 beta.)
42 replies on “Swift fun fact #1: You can use emoji characters in variable, constant, function, and class names”
[…] The day someone invents a programming language where you can use animated gifs as variables, it will be all over: globalnerdy.com/2014/06/03/swi… […]
If it is Unicode, why not post it as text?
(of course so I can copy and paste it into my current project !! muha ha ha ha…)
This is actually brilliant. It can help teaching programming to young people.
David Balažic: I tried to paste it into the blog entry, but it got mangled into those non-descript box characters as cut-and-pasted Unicode often is.
Stupid and useless, except for teaching programming to .. uh .. kids. Professional and experienced programmers know Roman characters and if you haven’t noticed yet, they have been using them to program everything till today, iCrap invention.
In Java, only letters and numbers are accepted, in any unicode alphabet. This means that emoticons, symbols and such are refused. But you can use the upside-down unicode character converter.
[…] As I wrote in an earlier post, it also lets you use emoji, which may be useful for amusing demos or in the event someone declares an Obfuscated Swift programming contest. […]
There is only one question remaining, why? Why would i check a variable to make sure if it’s a :) or kinky ;). Is this a teddy bear or a glass of wine. Totally useless but hey, it is apple, the new mirosoft!
Actually PHP can do it, too. I just made a sample from your code.
I have never thought about coding in emoji.
Anyway, it’s fun though….
see demo below.
http://tie.tw/emoji/emoji.php
Please make sure you view source code in Safari for proper emoji display.
http://tie.tw/emoji/emoji.php
Emoji is a bit silly, but the ability to use unicode characters opens a lot of doors – particularly if your first language isn’t english.
The only new thing about this is that “non-script” characters like Emoji can be used for identifiers (but why?). Unicode is valid in existing programming languages like Go:
http://play.golang.org/p/5D_1jJocd5
For some reason, the Go playground snippet link does not work when pasted into this comment system (but it works if directly pasted in to the URL bar). So, here is the code:
// You can edit this code!
// Click here and start typing.
package main
import “fmt”
func 世界() {
fmt.Println(“Hello,
This looked dumb and pointless, but the emoji part is not important. What IS important is the ability to use more than just ASCII.
For the domain I care about, math/physics, it means the ability to use variables names that are greek (and perhaps to be even more ambitious, we shall see — maybe a variable named ∫α rather than integralOfAlpha?)
Another domain where I could imagine this to be useful is code that is either targeting a foreign language, or targeting somehow translations between two languages. I’m sure if you’re Chinese, for example, you’d prefer to have your variable names in Chinese…
My former colleague worked for Japanese company. In Europe. The code they took over had comments in Japanese. You can probably imagine it wasn’t very helpful. Now consider what would happen if it had identifiers in Japanese as well.
Yeah, the real benefit of this is that you can program in Russian or Vietnamese or any other non-latin1 language and have the compiler understand you. The ability to use ridiculous Unicode dingbats is just an amusing side effect.
Everybody, take note of the first sentence in the article:
The emoji names are just a bonus for amusing demos.
A lot of languages allow unicode characters as identifiers. This is nothing new.
Yeah, and I’m working on Japanese project, in which they name variables by JAPANESE.
[…] Even gathering the information required to make an informed decision is almost certainly counterproductive. If, before embarking on a project, you actually took the time to analyze all the possibilities, and then climbed the resulting learning curve, you’d promptly get beaten to market by some teenager using PHP and Swift with emoji variable names– […]
[…] Even gathering the information required to make an informed decision is almost certainly counterproductive. If, before embarking on a project, you actually took the time to analyze all the possibilities, and then climbed the resulting learning curve, you’d promptly get beaten to market by some teenager using PHP and Swift with emoji variable names– […]
[…] Even gathering the tips required to make an informed determination is almost undoubtedly counterproductive. If, before embarking on a venture, you actually took the time to research the entire prospects, after which climbed the ensuing finding out curve, you’d at once get beaten to market through some teen the use of PHP and Swift with emoji variable names– […]
[…] Even gathering the information required to make an informed decision is almost certainly counterproductive. If, before embarking on a project, you actually took the time to analyze all the possibilities, and then climbed the resulting learning curve, you’d promptly get beaten to market by some teenager using PHP and Swift with emoji variable names[3]– […]
[…] Even gathering the information required to make an informed decision is almost certainly counterproductive. If, before embarking on a project, you actually took the time to analyze all the possibilities, and then climbed the resulting learning curve, you’d promptly get beaten to market by some teenager using PHP and Swift with emoji variable names– […]
[…] Even gathering the information required to make an informed decision is almost certainly counterproductive. If, before embarking on a project, you actually took the time to analyze all the possibilities, and then climbed the resulting learning curve, you’d promptly get beaten to market by some teenager using PHP and Swift with emoji variable names– […]
[…] Even gathering the information required to make an informed decision is almost certainly counterproductive. If, before embarking on a project, you actually took the time to analyze all the possibilities, and then climbed the resulting learning curve, you’d promptly get beaten to market by some teenager using PHP and Swift with emoji variable names– […]
[…] Even gathering the tips required to make an knowledgeable choice is almost for sure counterproductive. If, prior to embarking on a venture, you if truth be told took the time to research the entire prospects, after which climbed the ensuing studying curve, you’d instantly get beaten to market through some teen the use of PHP and Swift with emoji variable names– […]
[…] Even gathering the information required to make an informed decision is almost certainly counterproductive. If, before embarking on a project, you actually took the time to analyze all the possibilities, and then climbed the resulting learning curve, you’d promptly get beaten to market by some teenager using PHP and Swift with emoji variable names– […]
New challenge:
Write code that tells a funny story with emoji variable names that has nothing to actually do with what is going on in the code.
Mind = Blown.
You should define a custom exception class and call it (emoji for turd). Throw new (turd) … epic.
[…] Evan最后指出,面对乱花迷眼的开发语言、工具、框架和平台,开发者已经无所适从,选型、评估和试错的时间成本非常高,等你辛辛苦苦开工了,结果发现一个十几岁小孩用PHP和支持emoji表情符号的Swift开发的速度都比你快,甚至比你好。 […]
Nice to see other languages catching up to what Perl has had for a long time.
I can see it being used for code obfuscation, too.
This was fun!
https://gist.github.com/hasanadil/96bad711d6f71ec806f7
It is a pretty stupid feature, but from a language design standpoint, if you are going to allow other unicode characters for localization then it would be more difficult and error prone to remove emoji support than leave it in. That makes the decision an easy on because it also provides some serious comic relief.
if (.⚡() < .5 && !(.()) {.(); .⚠(" = ⏰!"); }
I could get used to this.
Great, looking forward to my first encounter with outsourced code using हिन्दी variable and function names.
Hello!
I wanna ask Jason Chiang something! My question is:
how did you made your sample that you made from the original code? I wonder because Im searching for a way to add emojis in php variables!
[…] Even gathering the information required to make an informed decision is almost certainly counterproductive. If, before embarking on a project, you actually took the time to analyze all the possibilities, and then climbed the resulting learning curve, you’d promptly get beaten to market by some teenager using PHP and Swift with emoji variable names— […]
[…] happen to be in the ranges allowed by the C++ spec, so if you've seen some of those examples of Swift code with emoji identifiers and were surprised by such capability you might be even more surprised to know that C++ has exactly […]
[…] above image is a (rather low-quality, sorry) screenshot of a real piece of code in Apple’s language Swift. Yes, despite its detestable looks, it is valid and compiles and […]
[…] language also allows emojis to be used by developers and less prone to […]