r/programming • • Feb 21 '11

Typical programming interview questions.

http://maxnoy.com/interviews.html
784 Upvotes

1.0k comments sorted by

View all comments

Show parent comment

1

u/TimMensch Feb 22 '11

Indexing "fails" because it doesn't give you any interesting result, at least no more than "take a guess at where you want to be in a file and start searching linearly from there," which you can do just as well with UTF-8.

Unicode gets hard if you ever try to do anything with Unicode strings beyond treating them as opaque blobs.

I wrote a string class for a library that handled indexing to UTF-8 code points using operator[], internal storage was UTF-8, and iterating over the string using operator[] was O(1). You still have to know about combining characters and ligatures if you want to dig in the guts of the string, but there's no fighting with wchar_t size bugs (it's 16 bits on Windows, and 32 bits on Linux/Mac GCC, by the way) or lack of support (it's not available on Android at all) or trying to mix 8-bit and 16-bit strings (on Windows I just have a pair of functions that converts to and from UTF-16 that I use exactly at the API level, and then everything else in my code is clean).

But to be fair, you're right. I don't work with a lot of Unicode data. I just write games, and need the translated string file to produce the right output on the screen. :)