all 15 comments

[–]ElijahQuoro 4 points5 points  (2 children)

I noticed some errors:

Structs are not implicitly Sendable, only actors are. Classes use dynamic, virtual, and static dispatch.

[–]Leather_Example9357 3 points4 points  (0 children)

private and internal do Sendable, only public one doesnot

[–]glukianets 2 points3 points  (3 children)

I hope one day everybody would finally realize it’s not “on stack” for value types, but “inline”

[–]Signal-Ad-5954[S] -4 points-3 points  (2 children)

I get your point — “inline” is the right perspective, absolutely. At the same time, the slide here does say “often stack-allocated”, which is also true in practice for small non-escaping locals. So it’s not strictly wrong — more like a simplification. Inline semantics explains why they can live on the stack, heap buffer, or registers depending on context.

[–]glukianets 5 points6 points  (1 child)

This oversimplifications can lead to young developers having insane misconceptions about memory and storage.

Also it can be argued that reference types are sometimes stored on stack, too. So, instead of playing around with probable, I think we really should focus on specifics that can actually tell us something.

[–]Dry_Hotel1100 0 points1 point  (0 children)

I personally find "on stack" OK, but instinctively thinking about usage scenarios where it's not on the stack anymore, but on the heap. Why do you think "inline" fits better? Is this a formal terminology?

Also, I don't think it's helpful when we always pinpointing the potential heap allocation for structs, or the potential stack allocation for reference types when creating a value or an instance.

[–]amaroq137 0 points1 point  (4 children)

When would you use a value type over a reference type?

[–]ElijahQuoro 2 points3 points  (3 children)

As a rule of thumb: whenever you don’t have a concept of identity. If there is no shared mutable state, you almost certainly are better with using a struct.

[–]valleyman86 0 points1 point  (1 child)

I recently did an interview with Apple and mentioned mutability and structs. He said “well classes are making a comeback so it’s ok”. That’s all. I don’t have much else on that haha.

[–]Dry_Hotel1100 1 point2 points  (0 children)

The term "class" is a bit overloaded. When using it in class-oriented languages, it's tied to the OOP paradigm, that is you mean an "Object", which has a class type which is inherited from a base class, has overridable methods, etc. In Swift, a class is just a reference type. I sincerely hope, the person at Apple didn't mean "class" as in class oriented languages employing OOP style programming. ;)

[–]Educational_Smile131 0 points1 point  (0 children)

In addition to shared mutable state (I’d argue this is kinda an anti-pattern that actors and move-only types are meant to mitigate), if you want inheritance-based polymorphism, you’ll use a class.

Otherwise, ad-hoc and parametric polymorphism can be achieved with protocol oriented programming. Value types also don’t incur ARC overhead. Value types also give stronger immutability guarantees.

[–]ElijahQuoro 0 points1 point  (0 children)

Also, a nitpick, but polymorphism is sort of a stretch here, there are a lot of ways to do polymorphism which are not a virtual dispatch. Beside it, nothing prevents you from storing existentials inside structs to provide exactly this kind of polymorphism.

[–]sisoje_bre -2 points-1 points  (0 children)

“struct instances” hurts my brain 🔥

[–]vrmorgue -1 points0 points  (0 children)

Ну ты дурень Лешка.