[swift-evolution] [Pitch] Eliminate tuples - unify member access syntax

Derrick Ho wh1pch81n at gmail.com
Sun Jan 8 13:11:18 CST 2017


On Jan 7, 2017, at 23:37, Derrick Ho <wh1pch81n at gmail.com> wrote:


I think pattern matching is the most compelling reason to keep tuples.


If they were gone, how would we replace the following?


switch (a, b) {

case (value1, value2):

case (value3, value4):

}



I really have to ask.  What do you use this for?  In general iPhone
application programming I have never wanted or needed to do that.  I do
some AudioUnits as well.  Still never needed it.


The alternative would be something like this
```
if a == value1 && b == value2 {
} else if a == value3 && b == value4 {
}
```

You would end up repeating boilerplate code.  Plus, the switch statements
guarantee that all cases are exhaustive while using a bunch of
if-statements would not.  A switch statement would force you to provide a
default case if you did not cover all the cases, but an if-statement
doesn't stop you.

Exhaustive switch statements are popular among low-level C programming
people that work with micro-controllers like Arduino.  I believe one of
swifts goals is to enter that territory.

On Sun, Jan 8, 2017 at 1:49 PM David Sweeris <davesweeris at mac.com> wrote:

>
> On Jan 8, 2017, at 09:33, Freak Show <freakshow42 at mac.com> wrote:
>
> On Jan 7, 2017, at 22:51, David Sweeris <davesweeris at mac.com> wrote:
>
>
> A really convenient way to pass around multiple values without having to
> bother with a formal struct.
>
>
> That's actually a big part of my concern.
>
> The people on this list are, I'm certain, among the top programmers
> working.
>
> I'm more worried about what happens when average (which IME means barely
> competent) developers get going with this.  I suspect nobody will ever
> declare a struct again.
>
>
> Doubtful, since tuples can't have any computed properties, functions, or
> conform to protocols.
>
> Type declarations are valuable - they are an opportunity to express
> intent.  OTOH, a pair of ints is a pair of ints and if all pairs of ints
> are type compatible then opportunities for catching errors drop if
> developers start favoring anonymous tuples over former structs.
>
>
> I don't think they are... "(Int, Int)" (without labels) will type-check to
> any pair of Ints, but IIRC "(x:Int, y:Int)" won't type-check to "(a:Int,
> b:Int)".
>
> On Jan 7, 2017, at 23:37, Derrick Ho <wh1pch81n at gmail.com> wrote:
>
>
> I think pattern matching is the most compelling reason to keep tuples.
>
>
> If they were gone, how would we replace the following?
>
>
> switch (a, b) {
>
> case (value1, value2):
>
> case (value3, value4):
>
> }
>
>
>
> I really have to ask.  What do you use this for?  In general iPhone
> application programming I have never wanted or needed to do that.  I do
> some AudioUnits as well.  Still never needed it.
>
>
> "Need" is a strong word... Yeah, I *could* switch over the first value
> and then for *every single case* nest another switch over the second
> value, but that'd be annoying *and* obscure the underlying logic.
>
> - Dave Sweeris
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170108/4badf3c3/attachment.html>


More information about the swift-evolution mailing list