[swift-evolution] [Pitch] String revision proposal #1

Karl Wagner razielim at gmail.com
Thu Mar 30 16:03:30 CDT 2017


> On 30 Mar 2017, at 21:39, Robert Bennett via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Adrian,
> 
> I think there are a few competing claims here.
> 
> 1) Substring is a term of art used universally throughout computing, and camel-casing it would run counter to that.
> 2) While subsequence is a word, its  precise mathematical meaning differs from what it means in Swift. In Swift a SubSequence contains consecutive elements of a sequence, whereas in math a subsequence may contain any subset of the elements, ordered correctly. Hence Subsequence would be technically incorrect (not a big issue IMO).
> 3) We want Sub[sS]tring and Sub[sS]equence to have the same capitalization.
> 
> I'd prefer ignoring 2 and satisfying 1 and 3, since there's no reason Swift's names must exactly coincide with mathematical objects with the same name (for instance, mathematical sets may contain anything at all, including themselves). In addition, the prefix "Sub" does not usually (ever?) produce a Sequence with wholly different mechanics, as do "Enumeration", "Zip2", etc. -- the Subsequence really belongs to the owning Sequence. So my vote is for Substring and Subsequence.
> 
> As for why not StringSlice... Substring is certainly a more familiar word. That said, StringSlice would make it clearer that the slice is a view into a String and is meant for temporary use only, which Substring might not convey. If we choose StringSlice, I see no reason to change SubSequence to Subsequence.
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

+ 1 to StringSlice. In fact, I’m not sure if we even need Substring/StringSlice at all. We already have a Slice type.

The proposal mentions the parallel to ArraySlice, but ArraySlice is set to go: https://bugs.swift.org/browse/SR-3631

So, running with the parallel, why not add a conditional conformance: "Slice: Unicode where Base: Unicode”?

- Karl
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170330/bc2ba4f6/attachment.html>


More information about the swift-evolution mailing list