2 ms·
> Swift stakes out one of the most interesting points in the design space by completely encapsulating the internal representation and requiring all accessors to
by astrange 5y ago
> Swift stakes out one of the most interesting points in the design space by completely encapsulating the internal representation and requiring all accessors to be explicit in whether they operate on the string's encoding (e.g. as UTF-8), its Unicode code points, or its grapheme clusters. All positions within the string are represented using abstract iterators that don't reveal their numeric quantities.
This is probably the only right way because 1. it admits multiple implementations (like packing into tagged pointers) and 2. a string isn't simply an array of anything. Strings are made of all of bytes/codepoints/grapheme clusters/words/lines/etc at different levels.
- adonovan 5y agoIf my survey revealed anything, it's that there is no one right way.