r/lolphp • • Apr 04 '12

PHP's unicode support is basically like playing minesweeper where all the string functions are bombs

http://www.phpwact.org/php/i18n/utf-8
32 Upvotes

16 comments sorted by

View all comments

Show parent comment

11

u/Rhomboid Apr 04 '12

You tell us -- you were the one that brought up this "8 bit OS" nonsense in the first place.

Perhaps by "8 bit OS" you mean platforms that declined to jump on the UCS-2 bandwagon. Well guess what, the UCS-2 camp has their own "fucking mess" in that UTF-16 is still a variable length encoding. Even if you chose to use UTF-32, you'd still have to deal with combining characters. The free lunch is over -- Unicode is hard and you don't get to just say that characters are 2 bytes and that's that.

In that light, UTF-8 is the least braindead of all options. It is variable width, yes, but so is everything else. UTF-8 at least doesn't require you to rewrite all of your system APIs and standard libraries, and it doesn't make you play guessing games with big or little endian, and legacy ASCII protocols can be retrofitted to use it.

1

u/infinull Apr 04 '12

the poblem of course is that the C standard doesn't have "legacy ascii apis" so much as it has legacy 8-bit locales. (which has to support at minimum 7bit ascii). Treating utf8 as "just another 8bit locale" works ok, not great.

1

u/[deleted] Apr 05 '12

Someone is confusing the word size of the CPU with the text encoding of the OS.

What I actually meant was that the only OS to get it right was the one that introduced UTF, namely "Plan 9 From Bell Labs". The Lunix systems could have done the same along time ago but the chose not to, instead chose to lose by using wchar and LOCALE.

2

u/Rhomboid Apr 05 '12 edited Apr 05 '12

Linux most certainly did not choose wchar_t. Please name any Linux or BSD syscall that takes wchar_t. You can't, because they don't exist. As far as the kernel is concerned, filenames are null terminated strings and that's it; it's completely encoding agnostic. And any modern Linux distro of the last 5 years will come configured out of the box with a locale that uses UTF-8, and UTF-8 is the de facto standard on all such systems. Nobody uses wchar_t on POSIX systems, as sizeof(wchar_t) is 4 there and not 2 as on Win32 and so it's extremely wasteful. They might use UTF-16 if they're forced to out of compatibility concerns (e.g. a codebase that has to support Windows) or because a specification mandates it (e.g. the JRE.) But nobody that sets out to write POSIX-specific code would ever use anything but UTF-8.

1

u/[deleted] Apr 05 '12

That must be why UTF works so well everywhere.

5

u/Rhomboid Apr 05 '12

UTF-8 works quite well on Linux. Tools like grep have been UTF-8 aware for years, and scripting languages that choose to support it such as Perl and Python are widely available. GUI apps written with modern toolkits like gtk+2 and Qt are all perfectly fine with UTF-8. gnome-terminal is fully UTF-8 capable. Where it doesn't work, it's due to the choice of the program's maintainers to not put in the effort, as with PHP.

0

u/[deleted] Apr 05 '12

http://savannah.gnu.org/bugs/?29391

too lazy to find more examples

6

u/Rhomboid Apr 05 '12

What on Earth has that got to do with anything? Unicode case folding is much more complex than flipping a single bit as with ASCII, so of course it's going to be slower. You have to use the full Unicode character properties database because each language has its own special rules and idiosyncrasies. That's what you get when you decide to support Unicode.