<blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div class="im" style="color: rgb(80, 0, 80); font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); ">> , or systems with very</div>
<div class="im" style="color: rgb(80, 0, 80); font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); ">> long uptimes that process arbitrary user-supplied data.</div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); "><div>
<span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); "><br></span></div></span><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); ">What relevance does this have to O(1) string indexing?</span></blockquote>
<br>Clearly, that comment was based on the string interning discussion, not O(1).<div><br></div><div>Sincerely,</div><div><br></div><div>jw</div><div><br></div><div>--<br>Americans might object: there is no way we would sacrifice our living standards for the benefit of people in the rest of the world. Nevertheless, whether we get there willingly or not, we shall soon have lower consumption rates, because our present rates are unsustainable. <br>
<br>
<br><br><div class="gmail_quote">On Sun, Oct 30, 2011 at 3:19 AM, Masklinn <span dir="ltr"><<a href="mailto:masklinn@masklinn.net">masklinn@masklinn.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On 2011-10-30, at 02:20 , Jon Watte wrote:<br>
><br>
> Life is too short to not normalize data on input, in my opinion.<br>
</div>"Normalization" does not mean "NFC". And NFC is not the best<br>
normalization form for all situations. Its only advantage really<br>
is in codepoint count.<br>
<div class="im"><br>
> However,<br>
> the specific examples I care about are all about parsing existing<br>
> protocols, where all the "interesting" bits are defined as ASCII subset,<br>
> and anything outside that can be lumped into a single "string of other<br>
> data" class without loss of generality. This includes things like HTTP or<br>
> MIME. Your applications may vary.<br>
><br>
</div>I think that is *by far* the biggest issue with many string datatypes:<br>
they double up as both "lightweight" structures in many ascii-based<br>
protocols, with those structures being either fixed-size allowing O(1)<br>
access (e.g. many logfile formats) or simple character-separated<br>
structures; and as actual encoding of *human text*, which is what Unicode<br>
was built for.<br>
<br>
These usages are completely at odds with one another: a byte/ascii-based<br>
structure is an array of bytes, some of which are visibly representable,<br>
but a unicode string is a *stream*. It is an array of codepoints, but<br>
codepoints are useless to manipulate text, and UTFs also map it to arrays<br>
of bytes but these byte arrays are also useless to manipulate text.<br>
<br>
To correctly manipulate text, in terms of code interface, the primary<br>
interface should be the grapheme cluster (what most people think of as a<br>
"character", although you *still* encounter the issue that a given codepoint<br>
sequence can be seen as one or several "characters" depending on the<br>
culture, I think *that* issue is much rarer than trying to manipulate<br>
grapheme clusters with codepoint-based interfaces). Furthermore, this<br>
manipulation should be done completely independently of the underlying<br>
physical representation (a grapheme cluster is expressed in terms of<br>
code points, not in terms of whatever code units the UTF uses).<br>
<br>
NSString is one of the very few string datatypes I've seen which makes<br>
treating text correctly easy (although it also includes the bytes/codepoint<br>
array stuff), because — while its primary interface is not grapheme clusters —<br>
it provides a very extensive interface to manipulate text in terms of<br>
grapheme clusters. I think its only issue is that it still allows for<br>
the manipulation of strings themselves in terms of codepoints and code<br>
units at all.<br>
<br>
Apple's even has a document on that very subject:<br>
<a href="http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Strings/Articles/stringsClusters.html#//apple_ref/doc/uid/TP40008025" target="_blank">http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Strings/Articles/stringsClusters.html#//apple_ref/doc/uid/TP40008025</a><br>

> It's common to think of a string as a sequence of characters,<br>
> but when working with NSString objects, or with Unicode strings in<br>
> general, in most cases it is better to deal with substrings rather<br>
> than with individual characters. The reason for this is that what<br>
> the user perceives as a character in text may in many cases be<br>
> represented by multiple characters in the string.<br>
<div class="im"><br>
>>> off very nicely. It seems truly bizarre to want string _indexing_<br>
>> (something I never<br>
>>> find useful, given the high strangeness of Unicode) to be O(1) but not<br>
>> to want<br>
>>> string _equality_ (something I do a lot) to be O(1).<br>
>><br>
><br>
> It seems like you never do network protocol parsing<br>
</div>Network protocol parsing is the manipulation of a bytes stream or a bytes<br>
array, by trying to fit this use case into a string datatype you're only<br>
ensuring this datatype will be garbage to use for text manipulation.<br>
<br>
You already have an erlang datatype to do network protocol parsing: binaries.<br>
<div class="im"><br>
> , or systems with very<br>
> long uptimes that process arbitrary user-supplied data.<br>
</div>What relevance does this have to O(1) string indexing?<br>
<div class="im"><br>
> I am coming at this from "I use binaries as strings now, and want something<br>
> even better" point of view.<br>
</div>Then you should ask for improvements of binaries, not for making a useless<br>
string type.<br>
<br>
I have the same view on this as Richard: for text (which is what Unicode was<br>
built for), O(1) indexing of code units and code points is useless.<br>
<br>
I also think the implementation details and performance characteristics of<br>
a string datatype should not be considered at all before it's being<br>
implemented, the first question should be what its interface looks like.</blockquote></div><br></div>