Live data from Hacker News

It’s not wrong that "🤦🏼‍♂️".length == 7 (2019)

hsivonen.fi

11–20 of 315 posts

Re: It’s not wrong that "🤦🏼‍♂️".length == 7 (2019)

#11

HN discards emojis in the title. The original emoji was https://emojipedia.org/man-facepalming-medium-light-skin-ton... which consists of 5 Unicode code points. Also please make sure to read the first heading after the title, which summarizes the whole point of this essay.

[deleted]

Re: It’s not wrong that "🤦🏼‍♂️".length == 7 (2019)

#12

HN discards emojis in the title. The original emoji was https://emojipedia.org/man-facepalming-medium-light-skin-ton... which consists of 5 Unicode code points. Also please make sure to read the first heading after the title, which summarizes the whole point of this essay.

That makes more sense. I'm sure there could be some language out there where a empty strings length could be 7.

Re: It’s not wrong that "🤦🏼‍♂️".length == 7 (2019)

#14

HN discards emojis in the title. The original emoji was https://emojipedia.org/man-facepalming-medium-light-skin-ton... which consists of 5 Unicode code points. Also please make sure to read the first heading after the title, which summarizes the whole point of this essay.

That makes more sense. I'm sure there could be some language out there where a empty strings length could be 7.

I have to admit, I gave that thought a bit too much time before I clicked the link and discovered what the title should have said

Re: It’s not wrong that "🤦🏼‍♂️".length == 7 (2019)

#16
Am I wrong for assuming the .length should return a length in bytes? If you want to use 32bit units, then multiply your output by 4.

If you want to do Unicode string manipulation and length counting, then use specific functions for that - but the base internal .length function should just output bytes.

Re: It’s not wrong that "🤦🏼‍♂️".length == 7 (2019)

#17
post #15

Python 3's approach is the most correct: Unicode defines text as a sequence of code points. UTF-whatever is an implementation detail.

Unicode defines text as a number of different types of things. They are sequences of codepoints, sequences of graphemes, sequences of graphime clusters. Furthermore, codepoints are different depending on how you normalize them. Accented characters can be written two different ways and have a different number of codepoints depending on how you write them (and if normalization is used)

Re: It’s not wrong that "🤦🏼‍♂️".length == 7 (2019)

#18
post #15

Python 3's approach is the most correct: Unicode defines text as a sequence of code points. UTF-whatever is an implementation detail.

Treating Unicode strings as a sequence of code points is a completely valid thing to do, but is usually not what you actually care about when dealing with text. Really, are code points any less of an implementation detail?

Re: It’s not wrong that "🤦🏼‍♂️".length == 7 (2019)

#19

HN discards emojis in the title. The original emoji was https://emojipedia.org/man-facepalming-medium-light-skin-ton... which consists of 5 Unicode code points. Also please make sure to read the first heading after the title, which summarizes the whole point of this essay.

Today I learned, that multi-glyph emojis are a thing.

Zero width joiner emoji sequences https://emojipedia.org/emoji-zwj-sequence/

Re: It’s not wrong that "🤦🏼‍♂️".length == 7 (2019)

#20
post #8

> Python 3’s approach is unambiguously the worst one, though. Did I miss the part where he explains this take? It's made up of 5 valid unicode code units. For a language where you're not supposed to need to know the byte size semantics, the correct length should be 5. What am I missing? The close second being 17, because length in bytes. Is another fine way to represent this data, e.g. what a successful write of some…

I think he meant to bring out defensiveness with that quip. He never says that it's a big deal, just that it's the worst way to get the length of a string containing emoji, presumably of the mainstream languages.

Why is it the worst way though?
Post reply on HN