[swift-evolution] [Pitch] Introducing role keywords to reduce hard-to-find bugs

Adrian Zubarev adrian.zubarev at devandartist.com
Fri Jun 16 14:20:34 CDT 2017


I’ve already mentioned this in this thread. This is one of the missing features from the generics manifesto, however it’s (almost) a syntactic sugar only. It means that if we would enforce default in Swift 4, then having default implementation directly inside protocols would be really a syntactic and additional change only, which is a good sign. ;)



-- 
Adrian Zubarev
Sent with Airmail

Am 16. Juni 2017 um 20:39:21, Tino Heth via swift-evolution (swift-evolution at swift.org) schrieb:

The described problem might be one of the most famous itches of the language, but imho the bar for new keywords* should be higher than that — and there are alternatives:

First, I guess many would like to see this to be valid Swift:

protocol Foo {
func bar() {
print("Default implementation called")
}
}

It's the most convenient way of avoiding typos: avoid to type ;-)
Imho this might already be enough, but for a full alternative for "default", I'd suggest something like this:

extension Foo {
func Foo.bar() {
print("String has its own implementation")
}
}

(to make it more familiar for those with a C++ background, "Foo::bar" could be used instead ;-)

Additional benefit: This wouldn't be limited to protocols — and it could possibly help in weird situations when two protocols declare functions with identical signature...

extension String: Foo {
func Foo.bar() {
print("String has its own implementation")
}

func Foo.barr() {
// compiler error, Foo defines no function "barr"
}

func barr() {
// this is fine, no connection to a protocol
}
}

- Tino

* well, I guess "default" is not really a new keyword… but you get the point
_______________________________________________
swift-evolution mailing list
swift-evolution at swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170616/aad04ec1/attachment.html>


More information about the swift-evolution mailing list