3 ms·
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
by rubiquity 11y ago
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.
- blazespin 11y agoThat's odd. You'd think most people would be coming from objc
- Moto7451 11y agoJust 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).
- mikeash 11y agoThe 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.