[swift-evolution] [SHORT Review] SE-0132: Rationalizing Sequence end-operation names

Xiaodi Wu xiaodi.wu at gmail.com
Tue Jul 26 03:57:13 CDT 2016


On Tue, Jul 26, 2016 at 2:01 AM, Daniel Duan <daniel at duan.org> wrote:

>
> On Jul 25, 2016, at 11:32 PM, David Hart via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>
>
> On 26 Jul 2016, at 06:50, Xiaodi Wu via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>    surface area and leverages the user's understanding of how ranges
>>    work.
>>
>>    It also implies we can replace
>>
>>      x.removingPrefix(n)
>>      x.removingSuffix(n)
>>
>>    with
>>
>>      x[$+n..<]
>>      x[..<$-n]
>>
>>   for Collections.
>>
>
> I'm not enamored of this suggestion. It succeeds in reducing API surface
> area, but at a severe cost to readability. You'd replace an unambiguous
> phrase (removing prefix or suffix), the meaning of which is further
> clarified by the consistent usage proposed in SE-0132, with a wordless
> spelling using some combination of [$+.<]. Cognitively, also, it
> substantially increases the burden for the reader: it replaces a single
> argument with a nested series of arguments; first, one must understand the
> meaning of the $ placeholder, then one must consider an addition or
> subtraction operation, then the formation of a range, and in the last
> example, the use of that range as a subscript argument--again, all
> wordlessly. Finally, subscripts have so far not been "forgiving," while
> today's `dropLast` very much is; this suggestion would add inconsistency by
> using a subscript for a forgiving or "lenient" operation.
>
>
> I second Xiaodi. I am against the slicing subscripts and the ones above
> look even more unreadable and inscrutable than those in the proposal. I
> don't understand the rational.
>
>
> The inspiration is D: https://dlang.org/d-array-article.html
>

Neat. However, $+n and $-n remain problematic for me, one additional reason
being that these suggest indices move themselves, which they no longer do
in Swift 3. Of course, we could (and, in fact, we would have to) say that
$+n is short for `x.index(x.startIndex, offsetBy: n)`, but that'd be a
pretty big contortion for the + operator.

> _______________________________________________
> 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/20160726/b14629f8/attachment.html>


More information about the swift-evolution mailing list