Live data from Hacker News

The string type is broken

mortoray.com

41–50 of 230 posts

Re: The string type is broken

#41
post #30
post #23

Do people really need to reverse strings in the real world? I don't think I've ever written code to do that outside of homework assignments and interviews.

Had such a case a few months back. Strings of single-byte characters are Endian-agnostic but multi-byte character encoding is affected by Endianness. To cope with it I read the sequence as single byte, then reversed, then changed the encoding to proper encoding and reversed again. The data came from a binary dump where I only needed a section that contained a few strings. I admit it's dirty but it was throwaway code…

Use UTF8, no endian issues. Thats yet another reason why UTF16 and UTF32 are broken.

Re: The string type is broken

#43

The string type isn't broken. If anything these "X is broken" posts are broken. Taking one special case, finding problems with that case and deducing that the whole concept must therefore be discarded is just silly. Strings work fine for the vast majority of use cases. No technology is free of flaws and engineering decisions are almost always based on weighting the pros and cons and choosing a solution that on balanc…

Exactly. Engineering =/= Maths.

Re: The string type is broken

#45
post #23

Do people really need to reverse strings in the real world? I don't think I've ever written code to do that outside of homework assignments and interviews.

May be not reversing, but trimming a Unicode string to certain character count is a close relative and it is a very common operation.

Re: The string type is broken

#46
Logically equivalent doesn't mean equivalent for computers. While you can't define why reverse of “noël“ is “lëon“ by set of rules that computer can follow, computer just can't know.

Re: The string type is broken

#47
post #2

Hat tip to Guido van Rossum for passing (nearly) all the tests in Python 3. Is the "ffl-ligature to uppercase" test really relevant? Isn't that fixed by appropriate use of string normalisation?

The ffl ligature passes

  $ python3
  Python 3.3.2+ (default, Oct  9 2013, 14:50:09) 
  [GCC 4.8.1] on linux
  Type "help", "copyright", "credits" or "license" for more information.
  >>> "baffle".upper()
  'BAFFLE'
Strange that the article claims that no languages passes it. It seems from another post that perl passes it too

Re: The string type is broken

#48
post #30

Earlier quoted context omitted.

Had such a case a few months back. Strings of single-byte characters are Endian-agnostic but multi-byte character encoding is affected by Endianness. To cope with it I read the sequence as single byte, then reversed, then changed the encoding to proper encoding and reversed again. The data came from a binary dump where I only needed a section that contained a few strings. I admit it's dirty but it was throwaway code…

Use UTF8, no endian issues. Thats yet another reason why UTF16 and UTF32 are broken.

language will not store unicode string internally with UTF8. Yes, we use it as input and output, but in memory, utf8 is terrible for random access characters. endian is only an issue (normally) for input and output, not really an issue for internal storage. especially when using UTF16 and UTF32 you know exactly the size of items.

Re: The string type is broken

#49
post #45
post #23

Do people really need to reverse strings in the real world? I don't think I've ever written code to do that outside of homework assignments and interviews.

May be not reversing, but trimming a Unicode string to certain character count is a close relative and it is a very common operation.

Right, but what's the count you want there? It's either a byte count or a grapheme cluster count. The .count() on most current languages' string types doesn't correspond to either of those, so isn't really useful.

Re: The string type is broken

#50
post #45
post #23

Do people really need to reverse strings in the real world? I don't think I've ever written code to do that outside of homework assignments and interviews.

May be not reversing, but trimming a Unicode string to certain character count is a close relative and it is a very common operation.

What do you use it for? Unless you have a monospaced font the number of characters do not mean much. So unless you are implementing command line tools or text editors it should not be that common.
Post reply on HN