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

Jessy Catterwaul mr.jessy at gmail.com
Sun Feb 7 09:44:56 CST 2016


I don’t believe this thread is well-served by having anyone be told why nested functions should not be nested functions. 

Now, the power of nesting won’t be fully realized until nested protocol extensions work. The majority of my nested functions are generic (much thanks to those behind 7.3’s compiler improvements for allowing me to bring a lot of those back into functions, when I had had to move them outwards.), and would be better served as extensions on a nested protocol. But, I still use nested structs, classes, functions, and computed properties a lot; they can be very good for limiting scope to exactly what is needed, and for eliminating duplicate code. 

So while I love the reasoning behind this proposal – the feature must be implemented, to avoid the ugliness that we deal with currently– I don’t like it as-is. I think the Swiftest way to do this is to use extensions for functions/properties/initializers.

I wager that initializers would benefit most:
http://merowing.info/2015/11/swift-init/ <http://merowing.info/2015/11/swift-init/>

extension init(coreDataStack stack: CoreDataStack) {…
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160207/46a79c6d/attachment.html>


More information about the swift-evolution mailing list