[swift-evolution] Strings in Swift 4
dabrahams at apple.com
Mon Jan 23 23:18:29 CST 2017
Sent from my iPad
> On Jan 23, 2017, at 9:50 AM, Ben Cohen <ben_cohen at apple.com> wrote:
>> On Jan 22, 2017, at 9:54 PM, Félix Cloutier <felixcca at yahoo.ca> wrote:
>>>> doesn't necessarily mean that ignoring that case is the right thing to do. In fact, it means that Unicode won't do anything to protect programs against these, and if Swift doesn't, chances are that no one will. Isolated combining characters break a number of expectations that developers could reasonably have:
>>>> (a + b).count == a.count + b.count
>>>> (a + b).startsWith(a)
>>>> (a + b).endsWith(b)
>>>> (a + b).find(a) // or .find(b)
>>>> Of course, this can be documented, but people want easy, and documentation is hard.
> These rules, while intuitive for some collections like Array, are not documented requirements of RangeReplaceableCollection & Equatable on which they rely.
While I agree wholeheartedly with the gist Ben's response here, I feel the need to clarify one thing:
The documentation doesn't have to spell out every possible law (theorem) explicitly as long as it is implied by what is documented (the axioms). For example,
is a law, and it's implied by this documentation:
Returns a Boolean value indicating whether the initial elements of the sequence are the same as the elements in another sequence.
If for some reason the rules above are not the inevitable consequence of documented semantics of RangeReplaceableCollection where Iterator.Element : Equatable, that is a bug.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution