3 ms·
> How is the memory management? Swift has both, reference types (heap allocated, refcounted) and value types (stack allocated (mostly)). Collections are copy
by adamnemecek 10y ago
> How is the memory management?
Swift has both, reference types (heap allocated, refcounted) and value types (stack allocated (mostly)). Collections are copy on write which is actually really dank. You don't really think about memory management much (compared with Obj-C). And if you do, I usually wrap it in some sort of abstraction so that I can write it and forget it.
The only modern language out of the three you mention is Rust. Swift is very similar to Rust but a bit higher level (but it seems like the languages will converge, a lot of the planned feature are creeping into Rust space). Swift is also simpler, but this is due to the fact that it's for a somewhat different purpose. A lot of the concepts are the same modulo the syntax. Rust was a major source of inspiration after all.
Writing it feels like writing this C++, JS, Python, Haskell hybrid. It's like the first language I actually enjoy writing (Rust is a better language but I'm not quite fluent).
That being said Swift isn't perfect but I things are getting fixed really quickly.
- deleted 10y ago[deleted]
- pcwalton 10y agoI wouldn't say Swift is simpler than Rust. The complexity is just in different places. For instance, Swift leans on OO quite heavily (as it has to for compatibility with Objective-C), and as a result its typechecker is quite a bit more complex: it's a full constraint solver as opposed to Rust's typechecker, which has a much simpler "expansion/contraction" heuristic. Of course, on the other hand, Rust has the whole lifetime system that complicates things.
- Gankro 10y agoYeah totally agreed. Swift is rife with way more special behaviours/magic to try to smooth over sloppy programming and just make stuff work. There's even a standard term for pushing a problem into the compiler: compiler heroics. Where heroics fall down, the language needs extra annotations to help the compiler out (@escaping closures is the most obvious). Swift also has a lot of slightly more ergonomic but otherwise largely unnecessary features: initializers vs static funcs, guards vs ifs, throws vs returning an enum, fileprivate vs private. Moving to working on Swift from Rust has led to me really appreciating how simple a lot of Rust really is. There's a lot of "oh it's literally just X". But the lifetime thing is a huge empowerer of Rust being simpler everywhere else. It means a lot more stuff can be "just X", because X can be made safe.
- paulddraper 10y agoWhy is COW collection "dank"?
- bluejekyll 10y agoAnd is "dank" good or bad?
- steveklabnik 10y agoIt usually means "good", though some people use it in an ironic sense to imply something is bad. Kinda like how "bad" can also mean "good" in the right context, but in reverse. Here I took it to mean "good."
- paulddraper 10y agoThe definition I am aware of is undeniably negative: "disagreeably damp, musty, and typically cold"
- steveklabnik 10y agoHa! I was so used to the... one I'm used to, that I forgot this obvious one. Seems like my analogy to "bad" was appropriate. "dank" as in "dank memes" as in "a word stoners use to describe good weed" is how I'm taking it to be used here.
- paulddraper 10y agoAh, well, I wouldn't know anything about that then ;)
- smitherfield 10y agoIt comes from stoner culture, where it's a sign of high quality when the psychoactive plant matter is still damp and smelly.