[swift-evolution] Final by default for classes and methods
Joe Groff
jgroff at apple.com
Mon Dec 21 12:31:21 CST 2015
> On Dec 21, 2015, at 10:04 AM, Dave Abrahams via swift-evolution <swift-evolution at swift.org> wrote:
>
>>
>> On Dec 20, 2015, at 3:51 PM, Michael Buckley via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>
>> +0. This seems reasonable, and a lot of the arguments are compelling. The argument put forth about library design especially so. But coming from C++, where I have to prefix nearly every method in my classes with virtual, I'm worried that we could end up with the same problem in Swift.
>>
>> We don't know what the dominant paradigm in swift will be ten years from now. Inheritance has a raft of problems, but there's no guarantee that the alternatives will be better in the long run. I suspect they will be, but I also suspect we will find new and exciting problems in large codebases using more functional patterns.
>>
>> While there's a lot of excitement in the Swift community right now about final, value types, and other language features, but I fear that when the rest of the world jumps on the Swift bandwagon, most are just going to use classes exclusively over structs and continue their OOP practices, simply because it's what they're used to.
>>
>> Making final the default may be a great way to discourage them. But it may also get us right back to where we are in C++ today, where programmers want virtual functions 99% of the time, but have to specify each function as virtual.
>
> In my considerable experience with C++, that is not at all where we are today. Increasingly, C++ is becoming seen as a language for high-performance computing, and people working in that area learn that they don't want to pay for virtual dispatch when they don't have to. It is true that for some of them, reflexive use of OOP is hard to shake, but they do learn eventually. Note also that Swift is really the second major language to take value semantics seriously. The first was C++.
In C++, you also often see polymorphic type erasure containers built on top of types that themselves don't require dynamic dispatch, like `boost::any`, `std::function`, and the like. This is something Swift makes first-class with protocols and protocol types. You don't need virtual dispatch of implementations as much if you can introduce ad-hoc virtual dispatch of interfaces at any point.
-Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151221/dc5a1d64/attachment.html>
More information about the swift-evolution
mailing list