News for hackers. Stuff that matters.
Re:Should I use a Swift struct or a class? by rubiquity on Saturday July 04, 2015 @01:37PM (#9830865)
I think the problem is that most people coming to Swift come from languages like Ruby and JS where just about everything is a reference (or pass by value where every value is a reference anyway). The distinction between value and reference is really hard to grasp when your background is in languages that are opaque like that. I remember Go had tons of questions of this nature early on in its adoption upswing.
Re:Should I use a Swift struct or a class? by mikeash on Saturday July 04, 2015 @08:44PM (#9832092)
The thing is, every language I'm familiar with has some types with value semantics. Numbers, for example, are pretty much always values. Pretty much nobody is surprised at the behavior of code like this in languages like Ruby and JS:

    var x = 42
    var y = x
    x++
    print x // 43
    print y // 42
It seems that, for whatever reason, people understand this but have a really hard time generalizing it. It's not even a matter of custom types being a confounding factor, as I've seen deep confusion over the fact that Swift collections have value semantics.
Re:Should I use a Swift struct or a class? by blazespin on Saturday July 04, 2015 @01:41PM (#9830881)
That's odd. You'd think most people would be coming from objc
Re:Should I use a Swift struct or a class? by Moto7451 on Saturday July 04, 2015 @03:29PM (#9831319)
Just the same in Objective C, unless you're dealing with a C struct (not being passed by pointer) or a primitive type you're in a sea of Objective C references. Value types are brand new to the non-Foundation framework ecosystem as far as writing new, stylistically correct, code is concerned. This in my experience does seem to be a sticking point for people without a good bit of experience in languages with the same or similar value and reference type split (C++, Java, C#, Rust, etc).