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

Adrian Zubarev adrian.zubarev at devandartist.com
Fri May 5 02:28:44 CDT 2017


I’m not arguing to remove all labels in Swift. Labels are great, this is a fact for sure. The point I was trying to make is that labels in tuples how either a meaning or not at all.

// This is a shortcut for the tuple type `(x: Int, y: Int)`
let foo = (x: 0, y: 0)  

// In this case the labels are only used for description,  
// they do not server any benefit here are most likely redundant
let (x: x, y: y) = foo  
Labels elsewhere are a different story and I do support the cosmetic addition Chris Lattner sketched out here: https://lists.swift.org/pipermail/swift-evolution-announce/2016-July/000233.html

However this is about closures and not tuples, I don’t think this would anyhow affect the removal of labels in tuple destructuring.

Plus I don’t see this to create an inconsistent in Swift, because as I already said, labels in tuple destructuring are useless.



-- 
Adrian Zubarev
Sent with Airmail

Am 5. Mai 2017 um 09:20:49, Xiaodi Wu (xiaodi.wu at gmail.com) schrieb:

On Fri, May 5, 2017 at 2:04 AM, Adrian Zubarev <adrian.zubarev at devandartist.com> wrote:
Personally I don’t see the latter as an issue, at least not in that particular example of yours, because you can always look up the type of your labeled tuple.

That's an argument that can be made for nearly all labels in the language, is it not? Function argument labels could be entirely removed, by your argument, since parameter names are completely visible in the documentation and you can always just look it up. Consider the rationale behind revising SE-0111 expressly to allow "cosmetic" labels. As I said, many languages don't have labels, but Swift does.

Is there any benefit gained from labels in tuple destructuring? let (x: x, y: y) is redundant to my eyes. If we ban reordering now, than I don’t see choosing different names in tuple destructuring as a strong argument of allowing labels there let (x: a, y: b). They’re literally the same as one would write comments inside the destructured tuple let (/* my x */ x, /* my y*/ y).

If you look in the C++ parts of the Swift compiler, that's the style for arguments in function calls where in Swift we use argument labels. Same idea. Your argument would remove most if not all labels from the language.



-- 
Adrian Zubarev
Sent with Airmail

Am 5. Mai 2017 um 08:36:20, Xiaodi Wu via swift-evolution (swift-evolution at swift.org) schrieb:

```
let tuple = (x: 1, y: 2)

// I, silly human, mistakenly think the elements in the tuple are
// `y` first, then `x`. I'm a confused human. Now I write:

let (y: y, x: x) = tuple
// Currently, does the right thing, even though I'm confused.

let (y: y, x: x) = tuple
// Without tuple reordering, this produces an error, which corrects my confusion.

let (y, x) = tuple
// Oops. I'm out of luck.
```

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170505/3777867e/attachment.html>


More information about the swift-evolution mailing list