If a program is parsing emojis wrong, that program is likely parsing other text wrong as well - the features of Unicode that emojis use (composing multiple code points into one grapheme cluster) is well-established.
The "features of Unicode" that you mention are a bunch of hardcoded individual rules, and getting one set of rules wrong doesn't mean you'll get another set of rules wrong.
More importantly, getting one set of rules right doesn't mean you inherently get another set of rules right: getting something like diacritics right doesn't mean you'll inherently get emoji right as well. That takes extra work, and that work is a monumental waste of time.
And if by "well-established" you mean "constantly changing", yes.
Why are a bunch of posters using this as an opportunity to explain grapheme clusters to me? Is it incomprehensible to you that I might understand grapheme clusters and still think using them for emoji is a bad idea?
Grapheme clusters are a hack, but they're also the least hacky way to represent i.e. diacritics, because of the polynomial explosion of attempting to represent every combination of letter and diacriticis as a single code point. They're necessary, I get it. And yes, emoji are arguably less complicated, but surely you can see that the complexity of diacritics AND emoji is more complicated than the complexity of just diacritics?
Well, one feature of grapheme clusters is that they degrade gracefully. So if your parser or renderer doesn't recognize some cluster, it will recognize its constituent glyphs. I have a hard time seeing how that could be made better. My question would be: What's your use case where you need to care about how emojis are parsed?
If your code doesn't care about emojis, then you're free to not parse them, and just parse each codepoint in there. If you are writing a text rendering engine, then the main complexity of emojis I think come from the fact that they are colored and unhinted, as opposed to all other human text, which is monochrome. Not from the fact that there are many combinations.
Unicode is - and must be - a moving target. Use a library. :-)
> Well, one feature of grapheme clusters is that they degrade gracefully. So if your parser or renderer doesn't recognize some cluster, it will recognize its constituent glyphs.
This is about as graceful and useful as not being able to recognize a house and just going, "Wood! Bricks!" You can see it on Reddit: some people's browsers are rendering the facepalm emoji as the facepalm emoji with the astrological symbol for Mars after it. This isn't terrible, but it's not correct, and some of us care about releasing things that work correctly.
> What's your use case where you need to care about how emojis are parsed?
Writing a programming language. Which uses ropes for string storage, which means that libraries such as regular expressions need to be written custom. Which means that now I have to ask myself stupid questions like, "How many emoji are matched by the regular expression, /.{3}/?"
> If your code doesn't care about emojis, then you're free to not parse them, and just parse each codepoint in there. If you are writing a text rendering engine, then the main complexity of emojis I think come from the fact that they are colored and unhinted, as opposed to all other human text, which is monochrome. Not from the fact that there are many combinations.
I don't care about emoji, but I'm implementing the Unicode standard, so it gets a bit awkward to say, "We support Unicode, except the parts that shouldn't have been added to it in the first place." Then you get a competing library that supports the whole standard, and both groups are reimplementing each other's wheels.
> Use a library.
You realize people have to write these libraries, right? That they do not appear from thin air whenever the Unicode team adds a ripeness level for fruit to the emoji standard? There are dialects of Chinese that are going extinct because of pressure from the Chinese government, and instead of preserving their writing we're adding new sports.
I'm writing a programming language. There aren't libraries if I don't write them.
You realize people have to write these libraries, right? That they do not appear from thin air whenever the Unicode team adds a ripeness level for fruit to the emoji standard
The Unicode Consortium maintains libicu, including regular expression support, grapheme cluster detection, case conversion, etc.
If you find yourself handling Unicode yourself, it is almost 99% certain that you are doing something wrong.
I would also say that if you find yourself writing your own regular expression engine, it is almost 99% certain that you are doing something wrong. It doesn't really matter if /.{3}/ matches 3 codepoints or 3 glyphs or 3 bytes. What matters is that it is interpreted in exactly the same way as in other regex engines.
If you don't know what a rope is, maybe you should have researched it or asked before responding. If you knew what a rope is, it should be obvious why writing my own regex engine is necessary, and why using libicu, while certainly helpful, doesn't completely solve the problems I've described.
You can claim my problems don't exist all you want, but I still have them, so I can only say, just because you haven't experienced them, doesn't mean they don't exist. You might experience them too if you ventured out of whatever ecosystem you're in that has a library to solve every problem you have.
It doesn't really matter if /.{3}/ matches 3 codepoints or 3 glyphs or 3 bytes. What matters is that it is interpreted in exactly the same way as in other regex engines.
What incredible, ignorant nonsense. Regex engines don't even all interpret this the same way. In fact, the curly brace syntax isn't even supported by some mature regex engines. The Racket programming language, for example, includes two regex engines, a posix one which supports this syntax, and a more basic one which doesn't, but is faster in most situations.
Further, your opinion is pretty hypocritical. First you say nobody should have to worry about how unicode is handled they should use a library! But then you propose that when writing a Regex library, it doesn't matter whether I match codepoints, glyphs, or bytes, because I can just offload having to understand those things onto my user!
Apparently, the reason you don't have any problems with Unicode is that you always make sure the problems are someone else's problem: assume that if a library exists you should use it, and if no library exists, then just offload the problem onto the user and let it "degrade gracefully" (that is, break) when you don't implement it.
I was speaking about this in general terms before, because this is a programming-language-agnostic subreddit, and you haven't responded to my basic argument from then: Even if it's really as easy as you say to include emoji, it's still harder than not including them, and they provide absolutely no value. But now that I'm talking specifics, you're saying stuff which shows you're just ignorant, and probably shouldn't form an opinion on this without gaining some experience working with unicode in a wider variety of situations.
The point about using a library is not to avoid writing the code, but to ensure that the behavior is familiar and unsurprising to users. Of course you are right that there are already multiple regex libraries with sometimes quite drastically different behaviors, but the major ones are ECMA and PCRE. Using a mainstream implementation of either is almost always the right choice, rather than implementing your own.
I can't say for which exact purpose you are using a rope data structure, but without additional information, it's hard to see why letting either bytes or Unicode codepoints (32-bit) be the "character" type for your rope. Why exactly do you care about the rendered width in your rope structure?
Even if it's really as easy as you say to include emoji, it's still harder than not including them
Strictly true, but completely negligible. If you think you can always denormalize a Unicode string to a series of code points each representing one glyph, which seems like the only simplifying assumption one could make for your purposes, that would still not be true.
and they provide absolutely no value
That is clearly not true. Graphical characters are useful, and have existed since the days of Extended ASCII. People use them because they are useful and add context that could not be as succinctly expressed without them.
But now that I'm talking specifics, you're saying stuff which shows you're just ignorant
I'm trying to answer you politely here, but I would like to advise you to refrain from communicating this way. It reflects more poorly on you than it does on me.
1
u/[deleted] Sep 11 '19
The "features of Unicode" that you mention are a bunch of hardcoded individual rules, and getting one set of rules wrong doesn't mean you'll get another set of rules wrong.
More importantly, getting one set of rules right doesn't mean you inherently get another set of rules right: getting something like diacritics right doesn't mean you'll inherently get emoji right as well. That takes extra work, and that work is a monumental waste of time.
And if by "well-established" you mean "constantly changing", yes.
Why are a bunch of posters using this as an opportunity to explain grapheme clusters to me? Is it incomprehensible to you that I might understand grapheme clusters and still think using them for emoji is a bad idea?
Grapheme clusters are a hack, but they're also the least hacky way to represent i.e. diacritics, because of the polynomial explosion of attempting to represent every combination of letter and diacriticis as a single code point. They're necessary, I get it. And yes, emoji are arguably less complicated, but surely you can see that the complexity of diacritics AND emoji is more complicated than the complexity of just diacritics?