[swift-evolution] InternalString class for easy String manipulation

Xiaodi Wu xiaodi.wu at gmail.com
Wed Aug 17 17:24:22 CDT 2016


On Wed, Aug 17, 2016 at 5:03 PM, Kenny Leung via swift-evolution <
swift-evolution at swift.org> wrote:

>
> > On Aug 17, 2016, at 1:57 PM, William Sumner <prestonsumner at me.com>
> wrote:
>
> > You may be interested in this article by Mike Ash, which gives a
> rationale for the String API, including why indexes aren't simple integers:
> https://www.mikeash.com/pyblog/friday-qa-2015-11-06-
> why-is-swifts-string-api-so-hard.html
>
> Thanks for the pointer.
>
> I guess being told *why* the String API is so hard doesn’t make me feel
> much better about the fact that it *is* hard.
>
> It opens:
>
> “One of the biggest complaints I see from people using Swift is the String
> API. It's difficult and obtuse, and people often wish it were more like
> string APIs in other languages.”
>
> It’s been said on the list that they are thinking about rewriting the
> String at some point. I’m hoping that the API can be made simpler.
>

I too am excited to see what improvements may come.

That said, the Swift String APIs are far and away *the best* string APIs
I've ever worked with, precisely because they promote _correct_ code in so
many ways that alternative "simpler" APIs don't. It's exactly this learning
process, where you learn that index-based slicing of NSString is unsafe and
that traversing Strings character-by-character is computationally
expensive, and then you find that you don't need to use either the unsafe
or the expensive methods after all, that reveals the power of the design.
As a result, you now have a Unicode-ready *and* performant slice algorithm.
The fact that you've been guided to this end result by the API design is
precisely what makes me appreciate it so much!


> -Kenny
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160817/7f2a8acf/attachment.html>


More information about the swift-evolution mailing list