Earlier quoted context omitted.
Totally see what you are saying (the underlying issue is language itself), but it's pragmatically obtainable.
The think is, strings that make sense has been a major goal of Swift, that's why they have been iterating on it so heavily. FWIW I think Swift's is probably one of the cleanest String abstractions out there with respect to unicode correctness balanced against efficiency and usability.
Swift UTF-8 String
81–90 of 97 posts
Re: Swift UTF-8 String
#82Earlier quoted context omitted.
> UTF-16 allows to quickly index a char in a string covering the most languages that way. Nope. UTF-16 is not UCS-2 anymore for multiple reasons. You cannot assume you can index a UTF-16 string as if it was UCS-2 anymore. UCS-4 (32-bit) is a possible option, though not generally recommended either. There are multiple tricks for getting great performance in UTF-8 string processing such as codepoint maps of various sor…
Never made a claim that UTF-16 is UCS-2. "Most languages" does not mean "all languages". Still, many popular platforms treat it like that in terms of char indexing. They are able to get away with it since a surrogate char is a rare guest in UTF-16. P.S. It's surprising how easily HN crowd downvotes something when it falls out of a whimsical "popular contemporary view on things". Having a lot of years of text processi…
Even if you are restricting "most languages" to mean "most programming languages", there's an increasing rise of emoji in comments alone for languages that support UTF-8 and some languages are picking up increasing emoji usage in places like identifier names.
Platforms that treat UTF-16 like UCS-2 and allow raw char indexing rather than codepoint-oriented traversal are wrong in 2019. (It's been wrong since the very definition of UTF-16, such as RFC 2781 in 2000.) UTF-16 is a disappointing hack because it allowed UCS-2 platforms the luxury of pretending that the UCS-2 era never ended. UTF-8 at least leaves you very aware that the UCS-2 emperor has no clothes.
Re: Swift UTF-8 String
#83Earlier quoted context omitted.
Unless you consider reference counting to be a form of GC¹, Swift is not a GC'ed language. ¹It technically is, but most people don't mean reference counting when they say GC.
It doesn't matter what people think, rather CS definition. Software Engineering is not about what people think, rather what is technically correct.
Re: Swift UTF-8 String
#84Earlier quoted context omitted.
Well.. what is technically correct depends on a definition. And there are customary/practical definitions too. And sometimes definitions are tainted by context, like in "is this gc or ref counting language".
Which should be "is this tracing GC or ref counting language". Naturally when in some juriditions one is allowed to call themselves engineers after a 6 months bootcamp we land in such customary/practical definitions.
What exactly are you trying to accomplish here?
Re: Swift UTF-8 String
#85Earlier quoted context omitted.
Totally see what you are saying (the underlying issue is language itself), but it's pragmatically obtainable.
Ah, so your solution is the same old canard: just ignore the complexity and call it pragmatic.
That's not 'ignoring complexity' and it's pragmatic.
That would help in English as it's really hard today just to deal emojis.
Re: Swift UTF-8 String
#86Earlier quoted context omitted.
Which should be "is this tracing GC or ref counting language". Naturally when in some juriditions one is allowed to call themselves engineers after a 6 months bootcamp we land in such customary/practical definitions.
Even wikipedia admits that most people mean tracing GC when they say GC. What exactly are you trying to accomplish here?
Re: Swift UTF-8 String
#87Earlier quoted context omitted.
Ah, so your solution is the same old canard: just ignore the complexity and call it pragmatic.
No. How about a string that returns a Unicode character length? That's not 'ignoring complexity' and it's pragmatic. That would help in English as it's really hard today just to deal emojis.
So even if you pick one definition and decide to live with it always... You'll still have to know what tradeoffs you (or an API designer or implementer) made.
Re: Swift UTF-8 String
#88Earlier quoted context omitted.
No. How about a string that returns a Unicode character length? That's not 'ignoring complexity' and it's pragmatic. That would help in English as it's really hard today just to deal emojis.
The point I tried to make: I suspect if you dug really deep into what is a character or glyph you might find "character length" is an imprecise and messy notion, with differing performance costs associated with differing definitions which may or may not apply to you. So even if you pick one definition and decide to live with it always... You'll still have to know what tradeoffs you (or an API designer or implementer)…
'It's complicated' is the utterly the wrong answer as to why we 'can't have better strings'.
Strings in almost every programming language were designed before Emjojis and true internationalization. If we designed them today, they would have support for dealing with most of the problems we face.
And FYI - there are not infinite corner cases. They are limited, and we can develop constructs for dealing with all of them.
Re: Swift UTF-8 String
#89Earlier quoted context omitted.
Ah, so your solution is the same old canard: just ignore the complexity and call it pragmatic.
No. How about a string that returns a Unicode character length? That's not 'ignoring complexity' and it's pragmatic. That would help in English as it's really hard today just to deal emojis.
That doesn't mean anything. Do you mean a code unit, a codepoint, a grapheme cluster, if the latter is it legacy, extended or tailored, how do you handle the locale dependency, … All of them can be useful in some context, all of them are length. And if anything, the truly useful one is the first one (because it tells you how much room you need to store something).
> That's not 'ignoring complexity' and it's pragmatic.
It's true that it's not ignoring complexity, because you're ignorant of it to start with. Which isn't really different.
> That would help in English as it's really hard today just to deal emojis.
It… really isn't.
Re: Swift UTF-8 String
#90Earlier quoted context omitted.
The point I tried to make: I suspect if you dug really deep into what is a character or glyph you might find "character length" is an imprecise and messy notion, with differing performance costs associated with differing definitions which may or may not apply to you. So even if you pick one definition and decide to live with it always... You'll still have to know what tradeoffs you (or an API designer or implementer)…
First - a combined unicode length is definitely universally useful. Second - a grapheme length is universally useful. Third - I didn't say 'pick one definition' - you did. A simple function which took as a parameter some kind of linguistic construct would be immensely useful in cases of choice/ambiguity. 'It's complicated' is the utterly the wrong answer as to why we 'can't have better strings'. Strings in almost eve…
As I said in another comment, I still applaud efforts to improve the status quo.