# [swift-evolution] [Proposal][Discussion] Deprecate Tuple Shuffles

Xiaodi Wu xiaodi.wu at gmail.com
Fri May 5 02:30:18 CDT 2017

```On Fri, May 5, 2017 at 2:27 AM, David Hart <david at hartbit.com> wrote:

>
> On 5 May 2017, at 09:24, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
>
> On Fri, May 5, 2017 at 2:22 AM, David Hart <david at hartbit.com> wrote:
>
>>
>> On 5 May 2017, at 07:56, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
>>
>> On Fri, May 5, 2017 at 12:54 AM, David Hart <david at hartbit.com> wrote:
>>
>>>
>>> On 5 May 2017, at 07:17, Robert Widmann via swift-evolution <
>>> swift-evolution at swift.org> wrote:
>>>
>>> On the contrary, this is precisely what it means to deprecate tuple
>>> shuffles.  You can’t map common parlance onto this term; the proposal and
>>> the Twitter thread weren’t merely about reordering arguments.
>>>
>>> but it is entirely another ballgame to remove labels from tuple patterns
>>> altogether.
>>>
>>>
>>> It’s really not.  Let me demonstrate:
>>>
>>> To be clear, are you proposing the prohibition of *adding or removing*
>>>> labels as well? A previous discussion on tuple shuffling on this list saw
>>>> consensus that assigning a value of type (label1: T, label2: U) to a
>>>> variable of type (T, U) and vice versa should absolutely be supported,
>>>> whether or not reordering is permitted.
>>>
>>>
>>> I am not proposing any changes to switching parameter labels through
>>> well-typed re-assignments.  This is absolutely still going to be allowed:
>>>
>>> var z : (Int, Int) = (0, 0)
>>> var w : (x : Int, y : Int) = (5, 10)
>>> z = w
>>> w = z
>>>
>>> This is modeled internally with a tuple shuffle, but not the kind of
>>> shuffle I’m interested in banning.  It’s a far simpler kind of
>>>
>>> And how about *restating* existing labels without any adding or
>>>> removing? To be clear:
>>>>
>>>> ```
>>>> let (partialValue: v, overflow: o) = 42.addingReportingOverflow(42)
>>>> ```
>>>>
>>>> ...involves absolutely no changes in labels whatsoever. The return type
>>>> is (partialValue: Int, overflow: ArithmeticOverflow).
>>>>
>>>
>>> That, however, is a kind of shuffle I intend to deprecate here.  This
>>> kind of pattern is subject to the “arcane syntax” part of the proposal.
>>>
>>>
>>>> Either one of these scenarios is commonly used, and it is astonishing
>>>> to me that they would be eliminated.
>>>
>>>
>>> Do you have proof of that claim? I have never seen the relevant kinds of
>>> tuple shuffle used before, and I doubt you have either before today.
>>>
>>>
>>> For what it's worth, I thought I knew Swift inside out and I had never
>>> seen or used the syntax your are proposing to ban, so I'm all for it.
>>>
>>
>> If you google "Swift tuple destructuring," it's demonstrated in the third
>> link you can click on. The article is even titled "best practices":
>>
>> https://github.com/terhechte/appventure-blog/blob/master/res
>> ources/posts/2015-07-19-tuples-swift-advanced-usage-best-practices.org
>>
>>
>> I do know and use tuple destructuring. But AFAIK, that’s not the syntax
>> Robert wants to ban: its the labels in that syntax. As he says:
>>
>> *Note that a tuple shuffle is distinct from a re-assignment through a
>> tuple pattern. For example, this series of statements will continue to
>> function as before:*
>> *(z, y, x) = (x, z, y)*
>>
>
> I'n not saying that you don't know about tuple destructuring. I'm saying
> that the particular feature Robert wants to ban is covered in the article I
> linked to, which at least Google thinks is one of the most relevant
> articles on tuple destructuring in Swift. So, it's not as rare as Robert
> makes it out to be; plenty of people have talked about it.
>
>
> The article is still called "Advanced Usage”. Its difficult to state how
> rarely or common a feature is used but my intuition tells me this is a very
> rare feature. If we’ve discussed it on this list, it has escaped me. And
> I’ve never seen it in the wild.
>

I'd agree that using this feature to reorder things is likely to be very
rare. However, you've actually never seen someone destructure a tuple using
labels? That's surprising to me. I feel _guilty_ every time I destructure a
tuple knowingly not writing labels! It feels...risky.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170505/fc398271/attachment-0001.html>
```

More information about the swift-evolution mailing list