5 ms·
> One issue to consider is that strings typically feature random access indexing of code points True but I find it's much rarer to actually need random access
by ChrisSD 7y ago
> One issue to consider is that strings typically feature random access indexing of code points
True but I find it's much rarer to actually need random access to arbitrary code points. Most of the time I either use strings as opaque "things" or I'm iterating through characters to find something interesting (e.g. parsing) where I can build my own index, if and when necessary.
I do agree with the article that if an abstraction is very leaky it's better to be upfront about that.
- richardwhiuk 7y agoI think that accessing characters by index is _probably_ a code smell in most places, especially if that string may contain arbitrary UTF-8.
- masklinn 7y agoAccessing string content by arbitrary indices is probably an error. Accessing string content by indices you got from previous lookups is useful for a number of situations.
- ben509 7y agoIt's usually wrong, but you have a large number of people who don't get regular expressions. It's hard to visualize an automata crawling over a string and handing out matches. The simpler mental model of splitting and splicing is easily grokable, so there's a lot of utility in supporting it.