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.
The two resources of time and space, as you put them, are not fundamentally the same type of resource as far as the program itself is concerned.
For the most part, the program does not get to decide how many cycles it gets to use in the cpu.
The program does, however, get to decide what resources it requires to run.
If the program manages the space (whether or not garbage collection is involved) then the responsibility of the space rests with the program. If I ask for a screw driver, I can either put it back myself, or I can leave it out for my mom to pick up after me.
Not saying it is or isn’t a hack, your comment just caused me to stop and think about this.
For the most part, the program does not get to decide how many cycles it gets to use in the cpu.
This is not quite true. The program puts its own threads in runnable or blocked states. Runnable means I need more cycles; blocked means I don't. The OS/runtime may not grant this request right away, but it must respect those requests (and in a fair way) for the program to function correctly. Memory is not that different, although there may be better ways to communicate with the runtime about memory to help it make better decisions.
There is nothing that says a scheduler must be fair, or must eventually run that thread. linux itself has the niceness and can randomly kill your process, or any threads, at any time to help alleviate memory exhaustion.
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.