> On Oct 27, 2017, at 10:51 AM, Mike Kluev <mike.kl...@gmail.com> wrote: > > On Thu, 26 Oct 2017 21:54:37 -0700 Slava Pestov <spes...@apple.com > <mailto:spes...@apple.com>> wrote: > > Closures cannot replace all uses of local functions. Local functions can be > recursive, and have a generic parameter list. > > > FTM, local functions do not help with "keep functions short" and "keep > indentation level small" rules of thumb.
So do structs and classes ;-) > what are the actual benefits of local vs non local functions? locality > principle? (define something where it is used). but we do not have it in much > more important cases, say, with static variables - we have to declare them > outside of functions. ditto for normal variables in extensions - no matter > how carefully i group functions in individual extensions based on their > purpose -- potentially in different files -- it all breaks once i need to add > a single variable to that group which i have to to in the class itself. Local functions can capture bindings from the outer function, just like methods can capture ‘self’ from the outer type. I don’t think a function with local functions is any less readable than a type declaration with methods. In many cases you can use both to solve the same problem, and the functional approach can be simpler. > what would be the damage if we remove local functions altogether, would we > lose anything really useful? aside from the fact that "it is too late at this > stage" i mean (which is appreciated). I mean, we could remove a lot of language features without giving up turing completeness. But I’ve personally used local functions in multiple languages and found them useful. I certainly don’t see why the feature is actively harmful, which is the criteria for introducing a source breaking change in Swift 5. Slava > > Mike >
_______________________________________________ swift-evolution mailing list swift-evolution@swift.org https://lists.swift.org/mailman/listinfo/swift-evolution