[swift-evolution] [Pitch] Introducing `Unwrappable` protocol
david at hartbit.com
Wed Mar 8 00:57:27 CST 2017
> On 7 Mar 2017, at 21:41, Erica Sadun via swift-evolution <swift-evolution at swift.org> wrote:
>> On Mar 7, 2017, at 1:31 PM, Jonathan Hull <jhull at gbis.com <mailto:jhull at gbis.com>> wrote:
>> Would ‘if let foo = foo’ still be allowed?
> Existing code should to continue to work with `if let foo = foo`. I don't
> believe I put anything in-text about removing this, but if you see something
> let me know.
But there’s nothing in-text that states clearly that you are not removing the old syntax. I think it would be worth clarifying.
> -- E
>>> On Mar 7, 2017, at 12:14 PM, Erica Sadun via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>> I have been involved in several separate related draft proposals for discussions
>>> that were cut off about 4 months ago. I believe they meet the criteria for Stage 2,
>>> but I'm doing a poor job presenting them coherently on-list.
>>> Because of that, I'm going to start over here, hopefully pulling in all the details
>>> and allowing the community to provide feedback and direction. The following
>>> gist is an amalgam of work I was discussing with Xiaodi Wu, Chris Lattner, and
>>> David Goodine.
>>> https://gist.github.com/erica/aea6a1c55e9e92f843f92e2b16879b0f <https://gist.github.com/erica/aea6a1c55e9e92f843f92e2b16879b0f>
>>> I've decided to link to the gist rather than paste the entire proposal as that never seems to
>>> really work here.
>>> In a nutshell:
>>> Unwrapping values is one of the most common Swift tasks and it is unnecessarily complex.
>>> Consider the following solutions:
>>> Introduce an unwrap keyword for Optional values
>>> Introduce an Unwrappable protocol for associated-value enumerations.
>>> Apply unwrap to non-Optional values.
>>> Extend for and switch.
>>> Fix pattern match binding issues.
>>> Simplify complex binding.
>>> Unwrapping with conditional binding and pattern matching is unnecessarily complex and dangerous:
>>> Using "foo = foo" fails DRY principles <https://en.wikipedia.org/wiki/Don%27t_repeat_yourself>.
>>> Using case let .some(foo) = foo or case .some(let foo) = foo fails KISS principles <https://en.wikipedia.org/wiki/KISS_principle>.
>>> Using the = operator fails the Principle of Least Astonishment <https://en.wikipedia.org/wiki/Principle_of_least_astonishment>.
>>> Allowing user-provided names may shadow existing variables without compiler warnings.
>>> The complexity and freedom of let and var placement can introduce bugs in edge cases.
>>> -- E
>>> swift-evolution mailing list
>>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> swift-evolution mailing list
> swift-evolution at swift.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution