[swift-evolution] [Proposal] function "return" optional keyword.

Dennis Lysenko dennis.s.lysenko at gmail.com
Sat Dec 19 14:24:01 CST 2015


Yes, this would be strange in multiline functions with different execution
paths. It works well in Ruby because function return types aren't
annotated, so the final expression is always a valid return value. In
swift, I think it would have too much design overhead to figure out how to
reconcile it with explicit return types, to be worth it with multiline
functions. However, it would be great to have implicit return in single
line closures with named parameters and single line functions.

On Sat, Dec 19, 2015, 2:28 PM Step C via swift-evolution <
swift-evolution at swift.org> wrote:

> There was discussion of implicit returns on the forums a while back. Will
> try to find the link later. The Swift team chose explicit returns for
> better code clarity. I still think this was the right call, even though
> implicit returns are certainly attractive when writing code.
>
>
> > On Dec 19, 2015, at 12:45 PM, Tino Heth via swift-evolution <
> swift-evolution at swift.org> wrote:
> >
> > Afaik the concept is quite common when "everything is an expression",
> which can be a nice feature of a language:
> > It saves keystrokes, and allows constructs like
> > let value = switch key {…}
> > But as the let syntax was changed to work with delayed assignment, one
> major use case is solved in a different way, and I doubt that it fits into
> the Swift roadmap.
> > Imho clarity is reduced, and it can look a little bit odd to end a
> function with a line like
> > value
> >
> > On the other hand, nobody would be forced to skip the "return", and I
> guess it wouldn't be a complicated change in the compiler… so if you want
> to continue working on the proposal, I would evaluate how this change could
> be reflected in the docs.
> >
> > Tino
> > _______________________________________________
> > swift-evolution mailing list
> > swift-evolution at swift.org
> > https://lists.swift.org/mailman/listinfo/swift-evolution
> _______________________________________________
> 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/20151219/9e3ec816/attachment.html>


More information about the swift-evolution mailing list