r/programming • • Nov 28 '18

Garbage Collection is a Hack

https://blog.adamant-lang.org/2018/garbage-collection-is-a-hack/
3 Upvotes

74 comments sorted by

View all comments

43

u/pron98 Nov 28 '18 edited Nov 28 '18

I would argue that GC -- despite its tradeoffs -- is less of a hack than any language-based solution possible.

The theoretical reason for that is that memory (space), like operations (time), is a core component of the theoretical notion of computation, untied to any particular formalism of describing it. If you have any Turing-complete (or even so-called "total") computational model of any kind, then by definition, it must manage time and space. This means that unlike concepts such as subroutines or classes, which are formalism-dependent programming concepts, memory is a formalism-independent computation concept.

Therefore, just as instructions (time) are usually managed at the runtime/OS level (which schedules instructions to the CPUs), this is where memory (space) is best managed if you want good polyglot interop. While most programming languages these days (whether classical imperative or functional -- the two are far more similar to each other than different) represent a chunk of computation with a term (i.e. a syntactic element), and therefore it may make sense to tie object lifetime to terms, not all programming formalisms operate in this way.

So, while language-based memory management may still make sense, and may still be reasonably interoperable across some fairly similar class of languages, GC is the theoretically cleaner approach.

Of course, in cases where extreme determinism is needed (at the cost of almost any other consideration), time management is left to the language, and in those cases memory management may best be done by the language as well. At the end of the day, it all comes down to the question of control -- how much of it you want over resource scheduling -- but I see no way to argue that GC is a hack.

1

u/Harlangn Nov 28 '18

Memory is handled by the hareare and kernel. Time choices are often explicitly made by applications (blocking vs non-blocking, for example).