[swift-evolution] [Pitch] Make `return` optional in computed properties for a single case

Dennis Weissmann dennis at dennisweissmann.me
Sat May 28 00:28:16 CDT 2016


+ 1 from me as well for the already stated reasons.

- Dennis

> On May 28, 2016, at 2:15 AM, Matthew Johnson via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
> 
> Sent from my iPad
> 
> On May 27, 2016, at 6:15 PM, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> 
>>> The idea is simple:
>>> 
>>>   • Can we make return keyword optional in cases like this?
>>>   • Shouldn’t this behave like @autoclosure or @noescape?
>> 
>> This actually doesn't have anything to do with @autoclosure or @noescape. Any one-expression closure can omit the `return` statement and have an inferred return type.
>> 
>>> type A {
>>>   var characters: [Character] = …
>>>   var string: String { String(self.characters) }
>>>   var count: Int { 42 }
>>> }
>> 
>> Despite those inaccuracies, I do think that it's a good idea to permit single-expression accessors to omit the `return` statement; it will make them much less clunky. I would even extend this to cases where you use the `get` keyword:
>> 
>>   var string: String {
>>       get { String(self.characters) }
>>       set { characters = Array(newValue.characters) }
>>   }
> 
> +1.  And in single-expression functions as well.  This is something that should be consistent and allowed everywhere in the language.
> 
>> 
>> -- 
>> Brent Royal-Gordon
>> Architechies
>> 
>> _______________________________________________
>> 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 <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160528/5726dcc9/attachment-0001.html>


More information about the swift-evolution mailing list