[swift-evolution] Modernize Switch/Case Statements?
Craig Cruden
ccruden at novafore.com
Sat Jan 30 09:00:58 CST 2016
I would argue that if you are in need of multiple blocks within a function that your function is not focused or concise. Unlike a language like Java, you can define functions within another function which greatly improves code structure as it allows you to write chunks of code that is used multiple times in a function but no-where else.
Haravikk, curious — how big are these functions that you feel the need for multiple blocks?
> On 2016-01-30, at 21:51:18, Maximilian Hünenberger via swift-evolution <swift-evolution at swift.org> wrote:
>
>>
>> Actually, one thing we don’t have in Swift is the ability to just put blocks (curly braces) wherever we like, which in some languages is a useful tool for variable scope when you know you only need something for a short time, but might want to re-use the name. Currently they just result in a “trailing closure separated by multiple new-lines” warning, so they could perhaps be made available, in which event you could use them in larger case statements whenever you wished.
>
> Actually "do" can be used for variable scoping:
>
> do {
> let x = Something()
> }
> let x = SomethingElse()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160130/f0a5ad01/attachment.html>
More information about the swift-evolution
mailing list