[swift-evolution] Property Getter Return Statement

Tony Allevato tony.allevato at gmail.com
Sat Oct 7 12:22:44 CDT 2017

I think the important thing to consider is, what advantage would such a
feature provide *other* than to reduce keystrokes? (I don't personally
think that optimizing for keys pressed by itself should be a goal.)

In the case of closures, single expression closures without "return"
improve readability because such closures are often chained for functional
programming patterns:

    someArray.filter { $0.isFloopy }.map { $0.grobber }

Having "return" there would be noise that detracts from understanding
what's going on in that algorithm. It's also worth noting that in this
context, the closure *itself* is also an expression.

In functions, property getters, and subscripts, the same constraints don't
really hold. They're declarations, not expressions, so they don't chain
together and they're not subject to the same readability problems as
closure expressions.

On Sat, Oct 7, 2017 at 9:59 AM Nevin Brackett-Rozinsky via swift-evolution <
swift-evolution at swift.org> wrote:

> On Sat, Oct 7, 2017 at 11:24 AM, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
>> This has been brought up on the list before. For instance:
>> https://github.com/apple/swift-evolution/pull/608
>> Chris Lattner’s response at that time was:
>> ‘Just MHO, but I consider this syntactic sugar, not a fundamental feature
>> that fits the goal of Swift 4 stage 2.
>> ‘I’m also pretty opposed to doing it at any time. The rationale of
>> “implicit return” in closures is specifically because they are limited to a
>> single expression, which makes the semantics “obvious”. This was carefully
>> considered.’
> This objection is not applicable, because we are discussing the
> possibility to omit “return” exactly when there is a single expression in
> the getter.
> Nevin
> _______________________________________________
> 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/20171007/6a802659/attachment.html>

More information about the swift-evolution mailing list