[swift-evolution] [Discussion] Modernizing Attribute Case and Attribute Argument Naming
Brent Royal-Gordon
brent at architechies.com
Wed Feb 17 23:29:10 CST 2016
> @Autoclosure // was @autoclosure
> @Available // was @available
> @ObjC // was @objc
> @NoEscape // was @noescape
> @NonObjC // was @nonobjc
> @NoReturn // was @noreturn
> @Testable // was @testable
> @WarnUnusedResult // was @warn-unused-result
> @Convention // was @convention
> @NoReturn // was @noreturn
>
> In the revised design, the following example for Swift 2.2
>
> @warn_unused_result(mutable_variant="sortInPlace")
> public func sort() -> [Self.Generator.Element]
>
> becomes
>
> @WarnUnusedResult(mutableVariant: "sortInPlace")
> public func sort() -> [Self.Generator.Element]
Wow, I'm surprised by how much I hate this. Currently, all Swift keywords are entirely lowercase (ignoring things like `Type`, `Protocol`, and `dynamicType` which come after a dot). I think I've learned to half-ignore things that look like that, but capitalizing suddenly pulls the spotlight onto these keywords. I'm just not a fan.
I think we're better off renaming or redesigning `warn_unused_result` so that it's readable when it's all-lowercase with no underscores. Some ideas:
@onlyreturns func sorted() -> [Self.Generator.Element]
func sorted() -> @important [Self.Generator.Element]
Alternatively, we could reverse the semantic and make all all non-Void functions warn unless they have an attribute saying not to.
@ignoreresult mutating func updateValue(value: Value, forKey key: Key) -> Value?
mutating func updateValue(value: Value, forKey key: Key) -> @ignorable Value?
mutating func updateValue(value: Value, forKey key: Key) -> @convenience Value?
If we do that, we'll likely still want to be able to annotate non-mutating methods with their mutating variants (well, unless we think the compiler can guess based on the API Guidelines.)
@variant(mutating: "sort") func sorted() -> [Self.Generator.Element]
@alternative(mutating: "sort") func sorted() -> [Self.Generator.Element]
That opens the possibility of using `@variant(nonmutating:)` on mutating functions, too.
--
Brent Royal-Gordon
Architechies
More information about the swift-evolution
mailing list