[swift-evolution] Revisiting SE-0110

Víctor Pimentel Rodríguez vpimentel at tuenti.com
Fri May 26 03:39:07 CDT 2017


On Fri, May 26, 2017 at 7:57 AM, Gwendal Roué via swift-evolution <
swift-evolution at swift.org> wrote:

> > Furthermore, this probably comes up most commonly with dictionaries,
> since they're a sequence of tuples. The element tuple for dictionaries has
> element labels (key: Key, value: Value), so instead of writing `{ tuple in
> let (key, value) = tuple; f(key, value) }`, you could use the implicit
> argument and write `{ f($0.key, $0.value) }`.
> >
> > -Joe
>
> I've migrated a project from Swift 3 to Swift 4 (relevant commit:
> https://github.com/groue/GRDB.swift/commit/4f26cbcacf7b783c9c503f2909f2eb
> 03ef7930fe)
>
> Joe is right, dictionaries, as handy as they are, are particularly
> affected. But $0 is hardly a panacea.
>
> What I regret the most with the change is the lost ability to give
> *relevant names* to tuple elements (and sometimes with the forced
> introduction of a phony variable that has no relevant name (like "pair").
>
> Here are below four examples of regressions introduced by SE-0110:
>
> Example 1
> -        return columns.index { (column, _) in column.lowercased() ==
> lowercaseName }
> +        return columns.index { $0.0.lowercased() == lowercaseName }
>
> Example 2 :
> -            .map { (mappedColumn, baseColumn) -> (Int, String) in
> +            .map { (pair) -> (Int, String) in
> +                let mappedColumn = pair.key
> +                let baseColumn = pair.value
>
> Example 3 :
> -                .map { (table, columns) in "\(table)(\(columns.sorted().joined(separator:
> ", ")))" }
> +                .map { "\($0.key)(\($0.value.sorted().joined(separator:
> ", ")))" }
>
> Example 4 :
> -                dictionary.first { (column, value) in column.lowercased()
> == orderedColumn.lowercased() }
> +                dictionary.first { $0.key.lowercased() ==
> orderedColumn.lowercased() }
>
> Gwendal Roué


I have also migrated a couple of projects, and this appeared in every one
of them even if we didn't use any RX library. For example Alamofire has a
couple of errors due to this change. And the resulting code after applying
the Fix-It is, well, not pretty.

As you say, it will basically affect a lot of Dictionary API surface, not
only forEach but map, filter, etc.

SE-0110 seems to hinder the functional programming style, and I would
revert it because right now we know that the proposal was wrong as it
stated that the impact on existing code may be that only "minor" changes to
user code may be required:

<goog_1034749016>
https://github.com/apple/swift-evolution/blob/master/proposals/0110-distingish-single-tuple-arg.md
Impact on existing code

Minor changes to user code may be required if this proposal is accepted.
<https://github.com/apple/swift-evolution/blob/master/proposals/0110-distingish-single-tuple-arg.md#alternatives-considered>Alternatives
considered

Don't make this change.

-- 
Víctor Pimentel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170526/745657bf/attachment.html>


More information about the swift-evolution mailing list