[swift-evolution] Strings in Swift 4

Ben Cohen ben_cohen at apple.com
Fri Jan 20 19:55:57 CST 2017


> On Jan 20, 2017, at 2:58 PM, Saagar Jha via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Sorry if I wasn’t clear; I’m looking for indexing using Int, instead of using formIndex.


Question: why do you think integer indices are so desirable?

Integer indexing is simple, but also encourages anti-patterns (tortured open-coded while loops with unexpected fencepost errors, conflation of positions and distances into a single type) and our goal should be to make most everyday higher-level operations, such as finding/tokenizing, so easy that Swift programmers don’t feel they need to resort to loops as often.

Examples where formIndex is so common yet so cumbersome that it would be worth efforts to create integer-indexed versions of string might be indicators of important missing features on our collection or string APIs. So do pass them along.

(There are definitely known gaps in them today – slicing needs improving as the manifesto mentions for things like slices from an index to n elements later. Also, we need support for in-place remove(where:) operations. But the more commonly needed cases we know about that aren’t covered, the better)


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170120/4fc7362c/attachment.html>


More information about the swift-evolution mailing list