3 ms·
I fully endorse the general idea here, but this: > `someText.firstCharacter()` would have a return type of `text`, with logical length 1 is a huge mistake. T
by lisper 6y ago
I fully endorse the general idea here, but this:
> `someText.firstCharacter()` would have a return type of `text`, with logical length 1
is a huge mistake. There are operations that make sense on characters that do not make sense on texts whose length happens to be 1. The most obvious of these is inquiring about the numerical value of the unicode code point of a character. Conflating characters and texts-of-length-1 is a mistake of the same order as conflating strings and byte vectors. Python makes this mistake even in version 3. As a result, a function like this:
def f(s, n, m): return ord(s[n:m])
will return a value iff m is one more than n. Not good.
- donaldihunter 6y agoOnly if you ignore the rest of what the post said. First it should make things easy for ‘normal’ tasks, then it should make everything else possible. > Basically, users should definitely _not_ need to understand the deeper details of Unicode. They shouldn't need to understand and worry about different entities such as code units, code points, graphemes, and the like, though they should be able to extract such encodings on demand.
- lisper 6y agoExcept that the "users" of a string type are programmers, and a "normal task" for a programmer often requires things like this. I'll give you an example from a project I am currently working on: a spam filter. One of the things my filter does is count the number of Chinese characters in a string. I implement this as n1<=ord(c)<=n2 where n1 and n2 are integers representing the start and end of the range of Unicode Chinese characters. This seems like a "normal task" to me and I don't see how conflating characters and texts-of-length-1 would make this any easier.
- Koshkin 6y agoFunctors are everywhere. That's why we need monads!
- lisper 6y agoGnats and sledgehammers something something...