4 ms·
Pythonic Rust you’re speaking of sounds an awful lot like Swift.
by zer0zzz 4y ago
Pythonic Rust you’re speaking of sounds an awful lot like Swift.
- Ygg2 4y agoSwift uses ARC everywhere from what I recall. Sure it's ergonomic. But why not just go for full GC then?
- pjmlp 4y agoRC is a GC algorithm, so it is already there.
- oleganza 4y agoNo it is not. The whole point of GC is to collect cycles and not think about ownership, while Swift and Rust require you to think about ownership. In Rust you do so via borrow checker or explicit Rc/Weak wrappers. In Swift you do that via additional weak annotations (strong being the implicit default).
- Ygg2 4y agoGrandparent is correct. Reference counting is a garbage collection mechanism. In same way a bubble sort is a sort. It doesn't care about ownership either. Apart from some Swift specific optimizations iiuc. Full GC I mentioned is more of mark and sweep variety.
- furyofantares 4y agoAlright, malloc/free is also garbage collection then.
- Ygg2 4y agohttps://en.wikipedia.org/wiki/Garbage_collection_(computer_science) https://en.wikipedia.org/wiki/Garbage_collection_(computer_s... See Reference counting. Note lack of malloc/free.
- mattgreenrocks 4y agoRef counting is considered GC (despite the colloquial definition excluding it) because RC handles the same problem domain as full GC, even with drawbacks around cycles. malloc/free, on the other hand, are just ways to allocate and release memory. They're too low level to be garbage collection. See this excellent comment: https://news.ycombinator.com/item?id=32277088 https://news.ycombinator.com/item?id=32277088
- pjmlp 4y agoI advise some self education in CS contents regarding GC. You can start here, https://gchandbook.org/ https://gchandbook.org/ https://www.udemy.com/course/essentials-of-garbage-collectors https://www.udemy.com/course/essentials-of-garbage-collector...
- zer0zzz 4y agoNot true. Swift uses value semantics for structs and enums, arc for classes. The arc optimizer afaik is able to remove atomics when it can determine code is not used for multi threading too.
- Ygg2 4y agoThat sounds a lot like C# which uses GC everywhere except for structs. Having optional GC but integrated GC does lead to a schism in API libraries (see C#, D, etc.). From my experience it's hard to go no-GC in C# because a lot of libraries depend on GC.
- zer0zzz 4y agoYeah, same for enums in Swift. Although with classes in Swift it's not quite like a runtime GC. Static code is inserted to retain and release. Afaik the arc optimizer uses an ownership model to optimize placement of retain/releases. I have been out of C# programming for over a decade now, but in Swift most guidance actually discourage use of classes, while a lot of types in the stdlib use a "Copy on Write" pattern where a struct contains a class that acts as a backing store. This gives the type value semantics but guarantees assignments will be cheap, only when the backing data is modified and the reference count is not unique is the data copied.