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

Jens Alfke jens at mooseyard.com
Fri Jul 1 13:01:19 CDT 2016


> On Jul 1, 2016, at 10:28 AM, Nicholas Outram via swift-users <swift-users at swift.org> wrote:
> 
> class methods may mutate "mutable static variables” (singletons), which are dangerous in multi-threaded code.

This is the same argument zh ao made. But instance methods may also mutate static variables, so the fact that you’re calling a class method doesn’t make the call any more dangerous.

Moreover, mutating instance variables can be just as dangerous for multithreaded code (and is a more frequent source of bugs IMHO).

Really, the only significant difference is that a class method can’t modify instance variables, so from that perspective it’s actually a bit safer than an instance method call!

—Jens
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160701/cc7d764e/attachment.html>


More information about the swift-users mailing list