[swift-evolution] Make non-void functions @warn_unused_result by default
Brent Royal-Gordon
brent at architechies.com
Wed Feb 24 20:32:30 CST 2016
> @optional_result (or ideally @optionalResult if camel-case for attributes is accepted) is clearer I think if we want a shortened two-word form.
I don't like "optional" here because it falsely implies a connection with the Optional type.
I do think, however, that this needs to be something very short—one or two words, not three or four. One way to trim words would be to attach the attribute to the return type; the position would imply that the keyword related to the return type, so the word "result" would be unnecessary:
@ignoreUnusedResult mutating func removeLast() -> Element
mutating func removeLast() -> @ignoreUnused Element
That might be a little strange, though—we don't currently have any attributes in that position.
Another way to make this shorter is to try to find an adjective which implies *why* we can ignore the result—that is, because it isn't important. The problem is that most such adjectives are either compound words:
@unimportantResult mutating func removeLast() -> Element
mutating func removeLast() -> @unimportant Element
@discardableResult mutating func removeLast() -> Element
mutating func removeLast() -> @discardable Element
Or they're uncommon words people may need to look up:
@banalResult mutating func removeLast() -> Element
mutating func removeLast() -> @banal Element
Actually, I can think of one word in the latter category that many programmers *do* know:
@trivialResult mutating func removeLast() -> Element
mutating func removeLast() -> @trivial Element
--
Brent Royal-Gordon
Architechies
More information about the swift-evolution
mailing list