You are right of course. I'm looking at this more from the eyes of an educator, where anything that reduces ambiguity helps. Students naively gravitating towards a singleton pattern is one of the battles I face. Some learners don't even properly understand the difference or risks. Invoking a static method can only mutate shared memory, making it a simple candidate for dangerous practise, so it's helpful when a language is explicit.
Ultimately you are right of course, as you say, instance methods can do this also. (Maybe it's also my own personal style / bias as I tend to avoid referencing static variables from instance methods where possible) Good discussion! Sent from my iPad > On 1 Jul 2016, at 19:01, Jens Alfke <j...@mooseyard.com> wrote: > > >> On Jul 1, 2016, at 10:28 AM, Nicholas Outram via swift-users >> <swift-users@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
_______________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users