[swift-evolution] Final by default for classes and methods
2th at gmx.de
Mon Dec 21 10:11:29 CST 2015
> This is obviously not a scientific sample and is not too large, but it is probably enough to give some sense of how inheritance is used by app developers as well as their opinions about final as default.
“I only believe in statistics that I doctored myself” - this quote is still true, and more than 95% of all statistic results are wrong ;-)
No, seriously, there are several arguments to not overestimate the value of the poll:
- There is bias in the form that you are more likely to view the poll submit a vote if you want final to be the default
- I bet no one really calculated the percentage numbers, but rather choose a value that fits better to his preferred result
- The poll starts with questions that filter out opponents that don't want to lie about their numbers (I could easily say I subclass everything just to change the numbers in favor of non-final… but that's not only unfair, but also easy to prove untrue :)
> "What percent of the classes you write are subclasses of classes other than Apple provided framework or open source library classes?”
> 66.67% indicate such subclasses only comprise 0-20% of the classes they write.
> 14.49% indicate such subclasses comprise 20-40% of the classes they write.
That's mostly building complicated numbers...
> 72.73% believe that final should be the default behavior.
No, this is a simple number without much room for interpretation: Nearly 3/4 of all who took part on the poll (that is an important aspect) want final to be the default. But wait...
> 48.48% prefer an `inheritable` keyword when inheritance is intended. An additional 15.15% prefer a `nonfinal` keyword for this behavior. 64.15% prefer one of the two. Only 36.36% prefer the current state of using `final`.
Hu? Three choices, and two are just different names for the same? And the numbers don't add up to the same values??
I can't see where "inheritable" is explained; naturally, I would take it as "you can extend what's already there, but not overwrite it"
> Obviously there are slight differences between questions that are effectively asking the same thing. My guess is that this can be attributed to misunderstanding of the question in some cases.
ah, ok - at least it's addressed
> The data points to a strong trend. Most classes written by respondents at the app level are not intended to be subclassed. Aligning with this trend in frequency, most of the respondents would prefer final to be the default behavior.
Which might be already the case — we are encouraged to use structs, and those can only be final.
One major differentiation for classes is that they can be subclassed, and if that is not wanted, maybe a struct would be better anyways…
Nonetheless, I still would switch to the "final by default" camp if you have a convincing answer to a simple question:
Why shouldn't inheritable (with the consequences outlined above) be the default? (if you read and answer at all, I'm fine when you discard the whole message if one this point is addressed…)
More information about the swift-evolution