Live data from Hacker News

Why can't you reverse a string with a flag emoji?

davidamos.dev

81–90 of 247 posts

Re: Why can't you reverse a string with a flag emoji?

#81
post #36

Earlier quoted context omitted.

UTF-8 reverse string has been a thing for a long time in most/all programming languages. It may not work perfectly in 100% of the cases, but that doesn't mean reversing a string is no longer possible.

> It may not work perfectly in 100% of the cases, but that doesn't mean reversing a string is no longer possible. I don't understand why in maths finding one single counter-example is enough to disprove a theorem yet in programming people seem to be happy with 99.x % of success rate. To me, "It may not work perfectly in 100% of the cases" exactly means "no longer possible" as "possible" used to imply that it would wo…

Because programming is not a science (or at most it is an applied science).

By your logic any software that has a single bug would be useless, and if that were the case this entire profession wouldn't exist.

Re: Why can't you reverse a string with a flag emoji?

#82
post #64

I'm not surprised the flag had two components, but I _was_ surprised the US flag was made by literally U and S, haha! I definitely thought it'd be something like [I am a Flag] and [The flag ID between 0 and 65535]. And reversing it would be [Flag ID] + [I am a Flag] which would not be a defined "component" and instead rendered as the individual two nonsense characters.

You might also have noticed this is partly a very well thought out hack to make Unicode less sensitive to disagreements and changes in consensus on which flags are encoded, or even the names of the countries concerned!

Re: Why can't you reverse a string with a flag emoji?

#83
post #21

I guessed that it would become the USSR flag (US -> SU), but apparently Unicode doesn't define that one! I wonder why. That would have been humorous.

IIRC Unicode doesn't define country codes. It was a workaround for a political issue of which countries recognize which other countries. It would have been difficult to get the CN delegation to sign off on a list that contained TW, although there are probably others.

There are many more than I realised - Wikipedia has a decent list https://en.m.wikipedia.org/wiki/List_of_states_with_limited_...

Re: Why can't you reverse a string with a flag emoji?

#84
post #55
post #36

Earlier quoted context omitted.

UTF-8 reverse string has been a thing for a long time in most/all programming languages. It may not work perfectly in 100% of the cases, but that doesn't mean reversing a string is no longer possible.

"It may not work perfectly in 100% of the cases, but that doesn't mean reversing a string is no longer possible." It depends on your point of view. From a strict point of view, it does exactly mean it is no longer possible. By contrast, we all 100% knew what reversing an ASCII string meant, with no ambiguity. It also depends on the version of Unicode you are using, and oh by the way, unicode strings do not come annot…

> By contrast, we all 100% knew what reversing an ASCII string meant, with no ambiguity.

Not if the ASCII string employed the backspace control character to accomplish what is today done with Unicode combining characters.

Or, in fact, if it employed any other kind of control sequence.

Re: Why can't you reverse a string with a flag emoji?

#85

If flag emojis are really a combination of 2 special characters, the reversal of the U.S. flag should result in having the Soviet Union flag.

It's up to the installed fonts really. I don't know if the combination of S + U is standardized as a Soviet Union flag emoji, but even if it is, your locally installed fonts may not contain every single flag emoji, so the browser would still fall back to rendering the two letters instead.

Re: Why can't you reverse a string with a flag emoji?

#86

Earlier quoted context omitted.

In my browser (Firefox on Windows), the thing between the quotes in the first block of code looks like a picture of the US flag cropped to a circle, not like the characters "us".

Ah I see, I just opened it in firefox. It looks like some JS library is not getting loaded in Edge. The author was talking about "us", "so", etc. looking like one character and I thought I was going crazy, lol.

There should not be any JS involved though, only a font able to render these grapheme clusters.

Do you see the US flag after "copy and paste this emoji" on https://emojipedia.org/flag-united-states/?

Re: Why can't you reverse a string with a flag emoji?

#87

Would be interesting to see the list of flag emojis that, when reversed, become a different flag emoji.

There are plenty of country codes that when reversed become a different, valid country code: e.g. Israel (IL) when reversed is Lithuania (LI); Australia (AU) becomes Ukraine (UA).

Whether "reversing flag emojis" causes such transformations will depend on what is meant by "reversing", which is kind of the whole point here: there are a number of possible interpretations of "reverse".

Re: Why can't you reverse a string with a flag emoji?

#88

But you can, and did, reverse a string. It seems you would need more details, such as a request to reverse the meaning or interpretation of the string, which is what the author is getting at. If someone challenges you to reverse an image, what do you do? Do you invert the colors? Mirror horizontally? Mirror vertically? Just reverse the byte order?

Galaxy brain image reversal: completely redraw it from scratch, with a viewpoint 180º from the original.

Re: Why can't you reverse a string with a flag emoji?

#89
Interesting article. Written for beginners, conversationally. Has excessive amounts of whitespace, for "readability" I guess. But at the same time, it dives quite deep, which I don't think this "style" of presentation matches up with the amount of time a more novice reader is going to devote to a single long form article.

As to the content, for all the deep dive, a simple link to https://unicode.org/reports/tr51/#Flags and what an emoji is, would have saved so much exposition. I also wish he'd touched on normalization. With the amount of time he's demanding from readers he could have mentioned this important subject. Because then he could discuss why (starting from his emoji example) a-grave (à) might or might not be reversible, depending how the character is composed.

Also wish he'd pointed to some libraries that can do such reversals.

Re: Why can't you reverse a string with a flag emoji?

#90

If flag emojis are really a combination of 2 special characters, the reversal of the U.S. flag should result in having the Soviet Union flag.

> the reversal of the U.S. flag should result in having the Soviet Union flag.

Except it has been deleted from the ISO 3166-2 registry, so not having it is perfectly valid (arguably more so than having it).

Post reply on HN