[swift-users] Why can't Swift instance methods call class methods without qualification?

zh ao owenzx at gmail.com
Fri Jul 1 12:14:52 CDT 2016


Your conclusion is the same as mine and you disagree with what I said? :/

mine:

> Swift forces you to use class name to alert you on the fact that static
> variables and methods (may) affect the other instances of the class as
> static variables are shared between instances. That does make sense.


y
​ours:

>  I think the reasoning behind this syntax is simply to make it easy to
> distinguish usages of static members (methods or variables) from instance
> ones.


Zhaoxin

On Sat, Jul 2, 2016 at 12:58 AM, Jens Alfke <jens at mooseyard.com> wrote:

>
> > On Jul 1, 2016, at 9:38 AM, zh ao <owenzx at gmail.com> wrote:
> >
> > Swift forces you to use class name to alert you on the fact that static
> variables and methods (may) affect the other instances of the class as
> static variables are shared between instances. That does make sense.
>
> I disagree. Both static and instance methods can affect other instances of
> the class. In other words, just looking at these two calls:
>         something()
>         MyClass.something()
> there’s no way to tell whether either or both of them change class-wide
> state. (To spell it out clearly: the implementation of the instance method
> something() might change the variable MyClass.staticState.)
>
> I think the reasoning behind this syntax is simply to make it easy to
> distinguish usages of static members (methods or variables) from instance
> ones.
>
> —Jens
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160702/6570d39b/attachment.html>


More information about the swift-users mailing list