[swift-evolution] Proposal: optionally define nested functions elsewhere

Amir Michail amichail at gmail.com
Sun Feb 7 09:03:06 CST 2016


> On Feb 7, 2016, at 10:00 AM, Alex Hoppen <alex at ateamer.de> wrote:
> 
> I don’t think this fits well in the current design of Swift. It reminds me a lot of (Obj-)C-style headers, which Swift abandoned. 
> 

The nested function bodies would need to occur in the same file.

> - Alex
> 
> 
>> On 07 Feb 2016, at 15:32, Amir Michail via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> The problem with nested functions is that they can make the function containing them very long and hard to read.
>> 
>> So the idea is to separate the body of a nested function from where it is declared.
>> 
>> For example:
>> 
>> func f() {
>> var x:Int
>> func g(y:String) {
>>   print(“x=\(x), y=\(y)")
>> }  
>> ...
>> }
>> 
>> could be refactored as:
>> 
>> func f() {
>> var x:Int
>> func g(y:String) // function body elsewhere to avoid clutter in f
>> ...
>> }
>> 
>> func f().g(y:String) {
>>   print(“x=\(x), y=\(y)")
>> }  
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 



More information about the swift-evolution mailing list