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…
The string type is broken
41–50 of 230 posts
Re: The string type is broken
#42Re: The string type is broken
#43The 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…
Re: The string type is broken
#44Re: The string type is broken
#45Do 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.
Re: The string type is broken
#46Re: The string type is broken
#47Hat 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?
$ 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 tooRe: The string type is broken
#48Earlier 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.
Re: The string type is broken
#49Do 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
#50Do 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.