Compiler Warning on Unextended Classes


(Rehat Kathuria) #1

I’d like the compiler to present a warning when a class not declared as final is never subclassed. Thoughts?


(Saagar Jha) #2

Correct me if I’m wrong, but if you’re writing some kind of framework and
your class is not final but never subclassed, you wouldn’t want the
warning, even if you’d like to allow users to subclass it?

···

On Thu, Jun 16, 2016 at 9:02 AM Rehat Kathuria via swift-evolution < swift-evolution@swift.org> wrote:

I’d like the compiler to present a warning when a class not declared as
final is never subclassed. Thoughts?
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

--
-Saagar Jha


(Michael Peternell) #3

I think unextended classes shouldn't be a compiler warning.
They even shouldn't be an optional linter warning.

There is a class. It doesn't have subclasses because I may have not written them yet. The process of writing software has to be anticipated somehow. I have 2 options:

1) I write the superclass first. Didn't declare it as final. Now I have to live with the warning until I first subclass it. This is really bad, because it encourages the habit of ignoring warnings.
2) I write the superclass first and mark it final. Later I write a subclass and remove the 'final' keyword again. => This makes people mark classes as final just because they aren't yet subclassed. This is really bad, and it sends the wrong signals to fellow developers. Marking a class as final signals that the class shouldn't be subclassed; whereas under this proposal developers are encouraged to mark classes as final just because they are not yet subclassed.

Have you considered code evolution? Furthermore, having a non-final class that is not subclassed, is not a bug. Declaring a variable and then never using it, is in many cases a bug. Most warnings hint at a likely bug, this warning doesn't.

-Michael

···

Am 16.06.2016 um 11:55 schrieb Rehat Kathuria via swift-evolution <swift-evolution@swift.org>:

I’d like the compiler to present a warning when a class not declared as final is never subclassed. Thoughts?
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Jon Akhtar) #4

This seems like a better job for an external linter tool or extended
static analyzer.

On 6/16/16, 02:55, "swift-evolution-bounces@swift.org on behalf of Rehat
Kathuria via swift-evolution" <swift-evolution-bounces@swift.org on behalf

···

of swift-evolution@swift.org> wrote:

I¹d like the compiler to present a warning when a class not declared as
final is never subclassed. Thoughts?
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Sean Heber) #5

I would think this would not apply to public classes.

There has also been discussion in the past about making final the default - I don’t remember if that ever resolved into some kind of consensus or not, though.

l8r
Sean

···

On Jun 16, 2016, at 11:23 AM, Saagar Jha via swift-evolution <swift-evolution@swift.org> wrote:

Correct me if I’m wrong, but if you’re writing some kind of framework and your class is not final but never subclassed, you wouldn’t want the warning, even if you’d like to allow users to subclass it?

On Thu, Jun 16, 2016 at 9:02 AM Rehat Kathuria via swift-evolution <swift-evolution@swift.org> wrote:
I’d like the compiler to present a warning when a class not declared as final is never subclassed. Thoughts?
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution
--
-Saagar Jha
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(L Mihalkovic) #6

Likely a lint level feature, no?

···

On Jun 16, 2016, at 6:27 PM, Sean Heber via swift-evolution <swift-evolution@swift.org> wrote:

I would think this would not apply to public classes.

There has also been discussion in the past about making final the default - I don’t remember if that ever resolved into some kind of consensus or not, though.

l8r
Sean

On Jun 16, 2016, at 11:23 AM, Saagar Jha via swift-evolution <swift-evolution@swift.org> wrote:

Correct me if I’m wrong, but if you’re writing some kind of framework and your class is not final but never subclassed, you wouldn’t want the warning, even if you’d like to allow users to subclass it?

On Thu, Jun 16, 2016 at 9:02 AM Rehat Kathuria via swift-evolution <swift-evolution@swift.org> wrote:
I’d like the compiler to present a warning when a class not declared as final is never subclassed. Thoughts?
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution
--
-Saagar Jha
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Xiaodi Wu) #7

Likely a lint level feature, no?

Agreed. Sounds like a linter feature.

···

On Thu, Jun 16, 2016 at 11:39 AM, L. Mihalkovic via swift-evolution < swift-evolution@swift.org> wrote:

> On Jun 16, 2016, at 6:27 PM, Sean Heber via swift-evolution < > swift-evolution@swift.org> wrote:
>
> I would think this would not apply to public classes.
>
> There has also been discussion in the past about making final the
default - I don’t remember if that ever resolved into some kind of
consensus or not, though.
>
> l8r
> Sean
>
>
>> On Jun 16, 2016, at 11:23 AM, Saagar Jha via swift-evolution < > swift-evolution@swift.org> wrote:
>>
>> Correct me if I’m wrong, but if you’re writing some kind of framework
and your class is not final but never subclassed, you wouldn’t want the
warning, even if you’d like to allow users to subclass it?
>>
>>
>>
>> On Thu, Jun 16, 2016 at 9:02 AM Rehat Kathuria via swift-evolution < > swift-evolution@swift.org> wrote:
>> I’d like the compiler to present a warning when a class not declared as
final is never subclassed. Thoughts?
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution@swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>> --
>> -Saagar Jha
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution@swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution@swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Rehat Kathuria) #8

Agree with Sean that this shouldn’t apply to classes declared public; I also don’t think the "default by final” discussion ever came to a consensus.

As for linters, my understanding of them is that they’re inclined to style-guides as opposed to architectural suggestions.The declaration of a class being final isn’t one that’s dependant on style, rather architecture.

···

On 16 Jun 2016, at 17:57, Xiaodi Wu <xiaodi.wu@gmail.com> wrote:

On Thu, Jun 16, 2016 at 11:39 AM, L. Mihalkovic via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
Likely a lint level feature, no?

Agreed. Sounds like a linter feature.

> On Jun 16, 2016, at 6:27 PM, Sean Heber via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
>
> I would think this would not apply to public classes.
>
> There has also been discussion in the past about making final the default - I don’t remember if that ever resolved into some kind of consensus or not, though.
>
> l8r
> Sean
>
>
>> On Jun 16, 2016, at 11:23 AM, Saagar Jha via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
>>
>> Correct me if I’m wrong, but if you’re writing some kind of framework and your class is not final but never subclassed, you wouldn’t want the warning, even if you’d like to allow users to subclass it?
>>
>>
>>
>> On Thu, Jun 16, 2016 at 9:02 AM Rehat Kathuria via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
>> I’d like the compiler to present a warning when a class not declared as final is never subclassed. Thoughts?
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution@swift.org <mailto:swift-evolution@swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>> --
>> -Saagar Jha
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution@swift.org <mailto:swift-evolution@swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution@swift.org <mailto:swift-evolution@swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution


(Saagar Jha) #9

I think that linters are the best way to handle this. It’s not really a
code smell that should always be taken care of (which would indicate that
the compiler should warn about it), and as such should be relegated to the
linter.

···

On Thu, Jun 16, 2016 at 10:08 AM Rehat Kathuria via swift-evolution < swift-evolution@swift.org> wrote:

Agree with Sean that this shouldn’t apply to classes declared public; I
also don’t think the "default by final” discussion ever came to a consensus.

As for linters, my understanding of them is that they’re inclined to
style-guides as opposed to architectural suggestions.The declaration of a
class being final isn’t one that’s dependant on style, rather architecture.

On 16 Jun 2016, at 17:57, Xiaodi Wu <xiaodi.wu@gmail.com> wrote:

On Thu, Jun 16, 2016 at 11:39 AM, L. Mihalkovic via swift-evolution < > swift-evolution@swift.org> wrote:

Likely a lint level feature, no?

Agreed. Sounds like a linter feature.

> On Jun 16, 2016, at 6:27 PM, Sean Heber via swift-evolution < >> swift-evolution@swift.org> wrote:
>
> I would think this would not apply to public classes.
>
> There has also been discussion in the past about making final the
default - I don’t remember if that ever resolved into some kind of
consensus or not, though.
>
> l8r
> Sean
>
>
>> On Jun 16, 2016, at 11:23 AM, Saagar Jha via swift-evolution < >> swift-evolution@swift.org> wrote:
>>
>> Correct me if I’m wrong, but if you’re writing some kind of framework
and your class is not final but never subclassed, you wouldn’t want the
warning, even if you’d like to allow users to subclass it?
>>
>>
>>
>> On Thu, Jun 16, 2016 at 9:02 AM Rehat Kathuria via swift-evolution < >> swift-evolution@swift.org> wrote:
>> I’d like the compiler to present a warning when a class not declared
as final is never subclassed. Thoughts?
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution@swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>> --
>> -Saagar Jha
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution@swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution@swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

--
-Saagar Jha


(Kevin Lundberg) #10

It seems to me that such a linter would need to scan the entire module
to determine if a class is subclassed, provided that it is internal. My
understanding of linters is that they typically don't do static analysis
of this sort, they are more targeted at local source or AST analysis.
Whole module optimization already looks at if an internal class is
subclassed in order to do its work, so presumably the same sort of
analysis would be required which suggests a compiler feature as I
understand it.

···

On 6/16/2016 4:32 PM, Saagar Jha via swift-evolution wrote:

I think that linters are the best way to handle this. It’s not really
a code smell that should always be taken care of (which would indicate
that the compiler should warn about it), and as such should be
relegated to the linter.

On Thu, Jun 16, 2016 at 10:08 AM Rehat Kathuria via swift-evolution > <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

    Agree with Sean that this shouldn’t apply to classes declared
    public; I also don’t think the "default by final” discussion ever
    came to a consensus.

    As for linters, my understanding of them is that they’re inclined
    to style-guides as opposed to architectural suggestions.The
    declaration of a class being final isn’t one that’s dependant on
    style, rather architecture.

    On 16 Jun 2016, at 17:57, Xiaodi Wu <xiaodi.wu@gmail.com >> <mailto:xiaodi.wu@gmail.com>> wrote:

    On Thu, Jun 16, 2016 at 11:39 AM, L. Mihalkovic via >> swift-evolution <swift-evolution@swift.org >> <mailto:swift-evolution@swift.org>> wrote:

        Likely a lint level feature, no?

    Agreed. Sounds like a linter feature.
     
        > On Jun 16, 2016, at 6:27 PM, Sean Heber via swift-evolution >> <swift-evolution@swift.org >> <mailto:swift-evolution@swift.org>> wrote:
        >
        > I would think this would not apply to public classes.
        >
        > There has also been discussion in the past about making
        final the default - I don’t remember if that ever resolved
        into some kind of consensus or not, though.
        >
        > l8r
        > Sean
        >
        >
        >> On Jun 16, 2016, at 11:23 AM, Saagar Jha via >> swift-evolution <swift-evolution@swift.org >> <mailto:swift-evolution@swift.org>> wrote:
        >>
        >> Correct me if I’m wrong, but if you’re writing some kind
        of framework and your class is not final but never
        subclassed, you wouldn’t want the warning, even if you’d like
        to allow users to subclass it?
        >>
        >>
        >>
        >> On Thu, Jun 16, 2016 at 9:02 AM Rehat Kathuria via >> swift-evolution <swift-evolution@swift.org >> <mailto:swift-evolution@swift.org>> wrote:
        >> I’d like the compiler to present a warning when a class
        not declared as final is never subclassed. Thoughts?
        >> _______________________________________________
        >> swift-evolution mailing list
        >> swift-evolution@swift.org <mailto:swift-evolution@swift.org>
        >> https://lists.swift.org/mailman/listinfo/swift-evolution
        >> --
        >> -Saagar Jha
        >> _______________________________________________
        >> swift-evolution mailing list
        >> swift-evolution@swift.org <mailto:swift-evolution@swift.org>
        >> https://lists.swift.org/mailman/listinfo/swift-evolution
        >
        > _______________________________________________
        > swift-evolution mailing list
        > swift-evolution@swift.org <mailto:swift-evolution@swift.org>
        > https://lists.swift.org/mailman/listinfo/swift-evolution
        _______________________________________________
        swift-evolution mailing list
        swift-evolution@swift.org <mailto:swift-evolution@swift.org>
        https://lists.swift.org/mailman/listinfo/swift-evolution

    _______________________________________________
    swift-evolution mailing list
    swift-evolution@swift.org <mailto:swift-evolution@swift.org>
    https://lists.swift.org/mailman/listinfo/swift-evolution

--
-Saagar Jha

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution