<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>On 16 Jun 2017, at 01:55, Xiaodi Wu via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:</div><div><br></div><blockquote type="cite"><div><div><div class="gmail_quote"><div>On Thu, Jun 15, 2017 at 17:43 David Hart <<a href="mailto:david@hartbit.com" target="_blank">david@hartbit.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><blockquote type="cite"><div>On 16 Jun 2017, at 00:41, David Hart <<a href="mailto:david@hartbit.com" target="_blank">david@hartbit.com</a>> wrote:</div><br class="m_7983055968534750193m_-786177547363741747Apple-interchange-newline"><div><div style="word-wrap:break-word"><br><div><blockquote type="cite"><div>On 15 Jun 2017, at 19:28, Chris Lattner <<a href="mailto:sabre@nondot.org" target="_blank">sabre@nondot.org</a>> wrote:</div><br class="m_7983055968534750193m_-786177547363741747Apple-interchange-newline"><div><div><div><br>On Jun 15, 2017, at 9:41 AM, Xiaodi Wu via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> o</div><blockquote type="cite"><div><div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><blockquote type="cite"><div><div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
><br>
> let (a : Int, b : Float) = foo()<br>
<br>
<br>
I think it would be better if the compiler raised a warning whenever you tried to redefine a builtin type.</blockquote><div><br></div><div>That’s essentially my preferred solution as well, as it gets to the root of the confusion.</div><div><br></div><div>Naming a variable the same as a type should be similar to naming a variable the same as a reserved keyword and require backticks. (A previous suggestion to enforce capitalization falls down with full Unicode support and complicates interop where imported C structures might be lowercase and constants might be all caps.) No need to treat built-in types specially; it’s equally a problem with types imported from other libraries, which can be shadowed freely today. For full source compatibility this can be a warning instead of an error–should be sufficient as long as it’s brought to the user’s attention. In fact, probably most appropriate as a warning, since the _compiler_ knows exactly what’s going on, it’s the human that might be confused.</div></div></div></div></blockquote><div><br></div></div></div><div style="word-wrap:break-word"><div><div>I kind of agree with all you say. But I also feel that tuple element names in patterns are very rarely used and not worth the added complexity and confusing. Going back to the old: “Would be add it to Swift if it did not exist?”, I would say no.</div></div></div></blockquote><div><br></div><div>That was the standard for removing features before Swift 3, but with source compatibility the bar is now much higher.</div></div></div></div></blockquote><div><br></div><div>Completely agreed. My belief on this is that it is a legacy Swift 1 type system capability that no one uses. I have no data to show that though.</div><br><blockquote type="cite"><div><div><div class="gmail_quote"><div> Is the feature harmful? </div></div></div></div></blockquote><div><br></div><div>Yes, absolutely. The shadowing isn't the thing that bothers me, it is that swift has a meaning for that very syntax in other contexts, and that this is completely different meaning. People absolutely would get confused by this if they encountered it in real code that they themselves didn't write, and I'm not aware of any good (non theoretical) use for it.</div><div><br></div><blockquote type="cite"><div><div><div class="gmail_quote"><div>My point is, not on its own it isn’t: warning on variables shadowing types is sufficient to resolve the problems shown here.</div></div></div></div></blockquote><div><br></div>Again, my concern is that this is a confusing and misleading feature which complicates and potentially prevents composing other features in the future.<div><div><br></div><div><br><blockquote type="cite"><div><div><div class="gmail_quote"><div><br></div><div>How strange that we’re talking about this issue in a thread about SE-0110. </div></div></div></div></blockquote><div><br></div><div><span style="background-color:rgba(255,255,255,0)">This came up in the discussion about 110 because we were exploring whether it was plausible to expand the function parameter grammar to support destructuring in the position where a name goes. There are many concerns about whether this is a good idea, but he existence of this in the tuple destructuring pattern grammar is pretty much a showstopper.</span></div><br><blockquote type="cite"><div><div><div class="gmail_quote"><div>If anything, the response to that proposal should be a cautionary tale that users can take poorly to removing features, sometimes in unanticipated ways.</div></div></div></div></blockquote><div><br></div><div>Agreed, it may be too late to correct this (certainly we can't outright remove it in Swift 4 if someone is using it for something important). However if it turns out that it really isn't used, then warning about it in 4 and removing it shortly after may be possible.</div></div></div></div></div></blockquote><div><br></div><div>And I think its difficult to make the parallel between the two. SE-0110 basically impacted everybody calling higher-order functions on Dictionary (+ more users from libraries like RxSwift), which makes an enormous proportion of the Swift community. On the other hand, despite the enormous amount of time I have sinked into learning, discussing and enjoying Swift, I never come upon the tuple element name syntax in patterns until Robert pointed to it out on twitter several weeks ago.</div></div></div></div></blockquote><div><br></div></div></div><div style="word-wrap:break-word"><div><div>By the way, I’m not attempting to deduce that nobody uses this feature by the fact I didn’t know about it. But I think it’s one interesting datapoint when comparing it to SE-0110.</div></div></div></blockquote><div><br></div><div><br></div></div></div></div><div><div><div class="gmail_quote"><div>SE-0110, **in retrospect**, has had impacts on a lot of users; prospectively, it was thought to be a minor change, even after review and acceptance.</div><div><br></div><div>Keep in mind that this proposed change would also eliminate inline tuple shuffle. For instance, the following code will cease to compile:</div><div><br></div><div><div>let x = (a: 1.0, r: 0.5, g: 0.5, b: 0.5)</div><div>func f(color: (r: Double, g: Double, b: Double, a: Double)) {</div><div> print(color)</div><div>}</div></div><div>f(color: x)</div><div><br></div><div>It is an open question how frequently this is used. But like implicit tuple destructuring, it currently Just Works(TM) and users may not realize they’re making use of the feature until it’s gone.</div></div></div></div></blockquote><br><div>It's much much less used, by looking at open source projects I doubt that a significant portion of projects would have to change code because of this.</div><div><br></div><div>--</div><div>Víctor Pimentel</div></body></html>