[swift-evolution] InternalString class for easy String manipulation
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>
> > 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:
> 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!
> swift-evolution mailing list
> swift-evolution at swift.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution