315 points · by raldu · 13y ago · 174 comments
I am a programmer. On my 1040 form, that is what I put down as my occupation. As a programmer, I write programs.
It would be great to create a website that showcases all of his contributions in detail.
I don't recall if Thompson is responsible for "modern" regular expression syntax--at least the `*` is borrowed from Kleene's notation. I'd look at Thompson's paper and find out, but I'm having trouble accessing my ACM subscription.
a(b|c)*d
without any description of what it meant, so I take it that at the very least, that much was borrowed from Kleene. I am having a hard time reading it, to see if anything else was implemented, as I am unfamiliar with Algol-60 or IBM 7094 assembly.He cites Kleene's paper, saying that he assumes the reader is familiar with regular expressions; I'd look at that paper and see what Kleene described, but I can't find a copy of that.
Thompson also site a paper by Brzozowski. The abstract for that paper includes: "Kleene's regular expressions, which can be used for describing sequential circuits, were defined using three operators (union, concatenation and iterate)"
Which I take to mean that Kleene only came up with the syntax expressed in the example expression at the beginning.
http://en.wikipedia.org/wiki/Euler_%28programming_language%2...
Anyway, 20 years later, hardware is still mostly 8-bit, and basically nobody cares about Unicode apart from font designers and the Unicode Consortium.
(On a side note, UTF-8 as a hack is a distant relative to Huffman encoding, itself a beautiful thing.)
The funny thing is that 16 bits wasn't enough.
We thought it would be, back then. Just use 16 bits for each character and we can return to the joy and simplicity of a fixed width encoding.
That didn't work out. UCS-2 was a fixed width 16-bit encoding, but it it had to be extended into the variable width UTF-16 to get more code points. You get the bloat of 16-bit data, incompatibility with ASCII, and variable width characters too.
You have to go all the way to UTF-32 to get back to a fixed width encoding.
So UTF-8 really was a smart move. Bite the bullet on the variable width, but make it so you can always find the beginning of the next character even if you start in the middle of one, and make it backward compatible with ASCII too. Genius.
https://en.wikipedia.org/wiki/UTF-8
UTF-32 appears to simplify things a lot, but in practice O(1) indexing of code points and simple iteration over code points is not actually all that useful, because code points are not characters.
If you to access code points, then UTF-32 gives you a nice fixed-width (albeit quite large) encoding to work with. Some applications or libraries may use UTF-32 internally to speed things up.
If you deal with things on screen or what humans perceive as character (graphemes) then there is nothing really that can help you at the encoding level because graphemes can be arbitrarily long with regard to code points: e̬̱ͤ̈́̿̂̅́͟x̰̞̻̼̻̼͉̰ͫͧ̑͂͊͜ͅa̶̳͖͔̞̰͈̯͓͆̓̎̉̏̎̚m̛̮̩͙ͦ͗͆̄̋́̄p͎̥̠͈̮͚̾ͅl̛̗̈̄e̴̞̫͖̝̘̋̑̄̎ͥͬ̾ (this probably doesn't even render properly).
Sadly, most APIs use either UTF-8 or UTF-16 and consider code units the most important entity, not code points. And that's inexcusable and frankly a mess, because I can count the number of times I needed to access a code unit instead of a code point on zero hands.
Unicode is a standard, that maps the giant number of letters to unique numbers.
UTF8 (and UTF16, UTF32) are various encodings of that. Unicode itself is not an encoding; unicode just says "letter 'č' is 269"; UTF-8 says "We will represent it as two bytes, first is C4, second is 8D".
UTF8 is indeed variable width; UTF16 and UTF32 are, AFAIK, fixed width. Both use unicode standard.
UTF-21, actually, as there are no code points above 0x10FFFF. Powers of two have other nice properties, though.
People still flame how MS uses 16-bit characters, which IMO is a bit of an unfair criticism. (Full disclosure: I used to work for them. But I was never a koolaid drinker.) I don't think they have any religious aversion to UTF-8, it's just history. By adopting Unicode as early as they did, they made this decision before UTF-8 existed and they stuck with it.
Probably the bigger crime is not switching to UTF-8 as the default "ANSI"/"multi-byte" codepage (to use the Windows terms). This means C programmers who are not Windows experts often end up writing non-Unicode-safe software because they expect every string to be char*.
(Also as has been mentioned UTF-16 is not fixed. And even in UTF-32 there are instances where a single glyph takes multiple code points - the decomposed accent marks are the one example I know, possibly there are others?)
This isn't just about UTF-16 either. Think about how much IE6 has cost everyone who's made a website in the last 10 years. Microsoft's penchant for building and marketing high-friction platforms is a huge drain on innovation (and a big barrier-to-entry for people who want to learn programming), and the company deserves an enormous amount of criticism for it.
Edit: put another way, the NT kernel since its inception represented and continues to represent all strings as 16 bit integers, saying that they need to "meaningfully address this" is like saying Linux should migrate away from 8-bit strings; there is no reason to do it. A lossless conversion exists and I fail to see it as a big deal, it's just a historical thing because NT's initial development predates UTF-8.
0x41 0100 0001 0x61 0110 0001
So if you want to test whether a character is uppercase or not, you can just & 0x20.
Another one is how the number digits got lined up, which start at 0x30 for 0 to 0x39 for 9, which look like:
0x30 0011 0000 0x31 0011 0001 0x32 0011 0010 etc.
You can just read off the first nibble to convert from ASCII to an int which is pretty cool.
Err, failure to parse sarcasm?
Most people on most networks use it daily. On mobile networks, it's used for tens of thousands of messages per hour as SMS messages in almost every country with non-Romanized scripts uses UCS-2 encoding. I've had to write a raw SMS PDU generator for a whole bunch of human languages, including right to left ones like Farsi and Arabic, or Chinese, Japanese, Korean and Thai. Furthermore, Unicode is now used by everyone in China, having finally mostly migrated from GB encoding. That means "most of the internet uses it daily".
I guess your point may have been sarcastic, because the above is obvious to me. Either that, or you have a really bad case of a merry centrism.
(Edit: I am not getting frustrated with you, rather my incapacity to grok the original post.)
That guy is probably using Shift-JS.
I doubt it.
Actually Baidu and other major sites are still on GB2312/GB18030. There are practical reasons as most of the frequently used (3000+ characters) Chinese glyphs take two bytes in GB2312, but three in UTF-8. Many URIs contain escaped GB2312 instead of escaped UTF-8. For mobile(, not only 3G, but more significantly, the GPRS/EDGE/WAP) users, every bit counts.
I couldn't write web software that deals with non-ascii, and especially non-Latin, alphabets without paying attention to Unicode.
When I start getting into weird edge and corner issues -- I am continually amazed that Unicode works as well as it does. It turns out modeling alphabets is way more complicated than you might think. And Unicode gets an amazing amount right, making it practical to do things robustly correct.
Including not just the character set and encodings, but things like Unicode collation algorithms. A bunch of really smart people have worked through a bunch of different non-trivial problems of dealing with diverse alphabets, and provided solutions you can use that pretty much just work, bug-free.
If by nobody you mean, pretty much the entire world east of New York.
(Yes, UTF-8 hack is nothing compared to Huffman coding. The Deflate compression algorithm using Huffman coding to encode the LZ77 output and the Huffman encoding table itself is another notch up on the hacking coolness scale.)
That said, at least they adopted a Unicode encoding, and helped it establish mindshare.
The real Java UTF-8 is, intuitively, named "AL32UTF8".
Between that and backwards compatibility with ASCII, I'd say it's a pretty neat hack.
The physical part of disks and networks usually have things like preambles, correlators, phase-locked loops, Gray codes, and self-clocking signals which can be used to deduce bit and byte boundaries, which is why in software, we almost always deal with information which we already know is correctly aligned.
You need to add extra bits so you can find the alignment, and once you do that you have the answer to your question.
He attempted to answer it, but the answer assumed that the recipient could recognize deleted characters, which doesn't make any sense to me (it seems to be rather like assuming that if someone sends you a postcard and you don't receive it, you nevertheless sense, at the time it would have arrived, that you should have gotten it).
It's funny to think that the concept of a fully functional typewriter would be foreign to Japan until dedicated computers could be built.
To me, that sounds both rather too teleological, and plausible.
My limited understanding is that it works like:
bits (0's and 1's) -> encoding (e.g. UTF-8) -> glyphs (e.g. Unicode) -> Some insanely complicated black box. This black box knows how to do all sorts of things like kerning, combining cháracters, bizarre punctuation,and other magic.
I understand UTF-8 and Unicode, but I have no idea how all the other magic works. Why is AV nicely kerned, and 我. nicely spaced? Apparenty this is a really hard problem because my trusty old code editor Textmate didn't get it right. Unicode to screen is a terribly hard problem.
Usually your desktop environment is the thing that handles all of this, providing widgets for other programs to combine to create GUIs. I can't find it right now, but you can probably find e.g. GNOME/GTK's implementation.
(Re: Textmate: code is typically rendered in monospace font -- where every glyph has the same size -- so that it has the same alignment in every font with every renderer.)
kerning: http://en.wikipedia.org/wiki/Kerning#Digital_typography
some stuff is embedded in the font, other things the OS will do on a "best guess" basis -- which is why things look radically different between operating systems and even between different apps on the same OS if they use their own font rendering.
Check out a very high-quality open source font rendering engine: https://developer.gnome.org/pango/unstable/
Really fascinating interviews with luminaries.
BAD_UTF8 = [\xC0\xC1\xF5-\xFF];
UTF8_CB = [\x80-\xBF];
UTF8_2B = [\xC2-\xDF];
UTF8_3B = [\xE0-\xEF];
UTF82 = UTF8_2B UTF8_CB;
UTF83 = UTF8_3B UTF8_CB UTF8_CB;
UTF8 = UTF82 | UTF83 ;
ATOM = ([_a-zA-Z]|UTF8)([_a-zA-Z0-9]|UTF8)*;This was as much as I needed to test my wide char code (and to parse written languages e.g. Chinese). At least left like this my code would error properly if it encountered a character it didn't know.
"The committee considered an eight-bit code, since eight bits (octets) would allow two four-bit patterns to efficiently encode two digits with binary coded decimal. However, it would require all data transmission to send eight bits when seven could suffice. The committee voted to use a seven-bit code to minimize costs associated with data transmission. Since perforated tape at the time could record eight bits in one position, it also allowed for a parity bit for error checking if desired.[17] Eight-bit machines (with octets as the native data type) that did not use parity checking typically set the eighth bit to 0.[18]"
http://randomtechnicalstuff.blogspot.com.au/2009/05/unicode-...
In some versions of BASIC (notably in Soviet versions and ABC BASIC), the currency sign was used for string variables instead of the dollar sign. It was located on the keyboard and the character set table at the same position in many national keyboards (like Scandinavian) and eq versions of 7-bit ISO/IEC 646 ASCII, as the dollar sign is in US-ASCII.
PS. This made me think of ₪, the sign for Israeli New Shekel. I wonder what percentage of currency symbols are completely symmetrical, and whether that derives from some kind of innate psychological quality that we associate with symmetry? IIRC, symmetry is oft-linked to beauty in the subconscious. (Of course, centrally issued fractional-reserve currencies nationally systematize usury, an activity universally shunned by all the world's monotheistic traditions, including Judaism: There are three Biblical passages which forbid the taking of interest in the case of "brothers," but which permit, or seemingly enjoin, it when the borrower is a Gentile [...] Lending on usury or increase is classed by Ezekiel [...] among the worst of sins. [...] abominations [...] be afraid of thy God [...] "...surely suffer death; his blood is upon him"; hence the lender on interest is compared to the shedder of blood. ... more @ http://www.jewishencyclopedia.com/articles/14615-usury)
You might also know Tom Jennings from having created Fidonet and having written the BIOS which became the basis for Phoenix Technologies BIOS.
Everything else he's far more detailed!
The specification of the format is at [1], although I would love to see a nice drawing of the hack.
[1] http://en.wikipedia.org/wiki/File_Allocation_Table#Long_file...
1. completely backwards-compatible with ASCII
2. you can always tell if you're reading a part of a multibyte character or not, meaning that you can tell if you're reading a message that was cut in some random point and can tell how many bytes to drop before reaching the first start of a character
3. endian-agnostic due to being specified as a byte stream
4. contains no null bytes, so it can fit in any normal C string
Point 1 is absolutely vital for backwards-compatibility and 2 makes it better than a lot of other multibyte encodings. Consider for instance chopping one byte off the start of a ucs2-encoded string - you'll get complete garbage. And 3 means you don't get strange endian-related errors.
It's a robust, resilient encoding that's a drop-in replacement for ASCII and needs no special support from many utilities - tail and head for instance can work with UTF8 text as if it's plain ASCII, just looking for a \n byte and chopping the input in lines.
So yes, I do think it's elegant. It may not be the simplest possible encoding for unicode, but it's extremely practical.
This is false; the encoding of codepoint 0 is 0x00 per the standard; modified utf-8[1] makes 0 a special case with an over-long encoding: 0xC0 0x80.
Well, yes. That's the point: 0x00 is only ever used to encode codepoint 0. It never shows up anywhere else. That's precisely what the text you replied to means.
A lot of people complain about not being able to easily or programmatically manipulate UTF-8 strings on a character-by-character basis, like it's a typical programmers daily business to go messing with natural language, but I've never seen the great loss.
It also turns out that you very rarely need arbitrary string indexing. Most of the time, when you're indexing into a string, it's a fixed (and relatively small) number of bytes from the start or end. UTF-8 can do this in a tight inner loop that just checks for bytes that don't start with 0b10. If you need .startswith or .endswith, you can just compare bytes with a byte length offset. If you need to do substring search, you can do Boyer-Moore on bytes. If you need to test for equality, do it on bytes. If you need to chop a string in half for divide & conquer algorithms and only need to be approximately right, you can chop in half by bytes and then use UTF-8's self-synchronizing property to find the nearest character boundary.
[1]: http://erlang.org/pipermail/erlang-questions/2011-October/06...
0xxxxxxx
the backward-compatible ASCII range 1xxxxxxx
means this doesn't stand alone, but is followed by another one (or more) complementary byte(s).This way, the ASCII range would be defined like the "first order", and the
1xxxxxxx 0xxxxxxx
would be the "2nd order" character range and so on! 1xxxxxxx 1xxxxxxx ... 0xxxxxxx
as N-bytes length sequence would form the "Nth order" character range (with an extensible N, of course).This kind of encoding would have accommodated any range! If I am missing something, I'm all ears.
The problem is that decoders cannot know what encoding a byte stream was encoded in without additional information. Such information are often lost or omitted as you can see in web world.
In such a situation, what decoders can do is just guessing. This is the reason why we still suffer Mojibake.
A possible solution was to attach encoding information to a head of bytes as one or two byte.
For example:
UTF-8 = 0b00000001
UTF-16 = 0b00000002
Shift_JIS = 0b00000003
EUC-JP = 0b00000004
and so on.
Of course this is not actual and reasonable solution because everyone must switch decoder/encoder to this protocol at once.