Hacker News new | ask | show | jobs
by frollogaston 393 days ago
The early pages of the Swift docs show you can use emojis as variable names, and iirc that was the very first page in the Swift 1.0 handbook. I have a theory that the language design was originally motivated by emojis, because there were also interesting choices around strings, like originally having no ".length" method.
1 comments

Here: https://docs.swift.org/swift-book/documentation/the-swift-pr...

Easter egg: The example is named dogcow, after a 90s Mac icon, designed by Susan Kare, which later became a small mascot: https://512pixels.net/dogcow/

Regarding .length: Effectly that is just the result of Unicode, there is no one-to-one equivalent between characters code points, the code units in an encoding and the resulting grapheme clusters. That is in effect a result of the complexity of the world's alphabets, including Emoji.

Yeah I get the justification for the lack of .length, but they eventually added it for a good reason too, which is that anyone calling that doesn't really care and those who do care can use something more specific.

The other aspects of strings are also centered around things being of uncertain length, like how it's O(n) to take the nth character of a string, and how there are rather complicated objects involved in taking substrings. There's a lot more thought and resulting complexity than other languages' default strings. And yes a few languages use extended grapheme clusters, but I feel like emojis were the real motivation.

To clarify, this tradeoff makes sense when you care a lot about complex emojis, but not so much otherwise. Other programming languages' strings can store grapheme clusters too but don't optimize around them. The only other example I found back then was a non-modern alternate Korean script.