16 ms·
a lot of implementation leverage (e.g. garbage collection) Putting garbage collection in that basket is controversial and lately the evidence is piling up agai
by WildUtah 10y ago
a lot of implementation leverage (e.g. garbage collection)
Putting garbage collection in that basket is controversial and lately the evidence is piling up against it.
Notice how new important growing languages like Swift and Rust don't have garbage collection and programmers don't miss it. GC is more and more restricted to low performance languages like Python, Javascript, and Ruby and a few specialized highly tuned and expensively engineered exceptions like the JVM and obscure LISP engines.
And if you've ever tried to program responsive, interactive, predictable, or time-critical systems, you know that GC is ruinous and awful for those applications. Meanwhile languages like Rust, Swift, and C++ can be used for everything from systems programming to games to low power mobile apps to scripting.
- lossolo 10y ago> Notice how new important growing languages like Swift and Rust don't have garbage collection Swift is using reference counting which is a form of garbage collection.
- stouset 10y agoThis is not what people are talking about when they say it doesn't have a garbage collector.
- david-given 10y agoSwift does have garbage collection! It uses reference counting, and AFAIK it doesn't have cycle detection, which means it's up to the developer to ensure that no cycles occur. Regarding responsive interfaces: pure reference counting is particularly problematic for this, because an unbounded amount of work may happen every time an object's reference is decremented (because the object might be freed, which causes other objects' references to become zero, etc). If this happens inside a critical section Your Life Is Pain. At least you can control when this happens by taking and then dropping an additional reference. (See Obj-C's allocation pools.) C++'s shared_ptr<>, BTW, is also reference counting, and suffers from the same problem. So it's technically correct (which is the best kind of correct) to say that C++ has garbage collection too.
- WildUtah 10y agoReference counting isn't garbage collection. It's the opposite of garbage collection. With reference counting, which is optional in C++ and can be opted out of in Swift, you keep track of your allocations and release them when you're done with them. With garbage collection an outside program decides when you're done with memory and deals with it for you on its terms. It's true that there can be unlimited work done in reference counting. Of course, it's true there can be unlimited work in any function of any program. [0] With reference counting a programmer can fix the amount of work to be done and when in deterministic fashion. With garbage collection, there is no such power. The gc decides when it will work and you cannot control or predict the interruption. You cannot produce serious interactive or time sensitive control software like that. You certainly can't write system software like that. [0] https://en.wikipedia.org/wiki/Halting_problem https://en.wikipedia.org/wiki/Halting_problem
- lossolo 10y ago> Reference counting isn't garbage collection. "Reference counting is a form of garbage collection"[1] [1] https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)#Reference_counting https://en.wikipedia.org/wiki/Garbage_collection_(computer_s...
- prodigal_erik 10y agoIf the runtime mechanically detects that an object will never be used again, without you having to explicitly say so (and woe unto you if you're mistaken), that's what's meant by garbage collection. Reference counting does have a deterministic cost, but it's extremely high and applies to everything you do. Copying collection benefits from deferring and batching the work when most objects die quickly and can be ignored with zero effort (just recycle the arena containing all of them).
- WildUtah 10y agoYou can write a reference counter in three short lines of code that works the same as shared_ptr<T> or Swift. A modern automatic garbage collector requires a threading library plus tens of thousands of lines of intricate code. We're not comparing like with like here.
- xioxox 10y agoPython mostly uses reference counting, but has a garbage collector which periodically checks for cycles. It's even possible to disable the garbage collector.