|
|
|
|
|
by masklinn
401 days ago
|
|
Destructors require deterministic cleanup, which advanced GCs can't do (and really don't want to either from an efficiency perspective). Languages with advanced GCs have "finalizers" called during collection which are thus extremely unreliable (and full of subtle footguns), and are normally only used as a last resort solution for native resources (FFI wrappers). Hence many either had or ended up growing means of lexical (scope-based) resource cleanup whether, - HoF-based (smalltalk, haskell, ruby) - dedicated scope / value hook (python[1], C#, Java) - callback registration (go, swift) [1]: Python originally used destructors thanks to a refcounting GC, but the combination of alternate non-refcounted implementations, refcount cycles, and resources like locks not having guards (and not wanting to add those with no clear utility) led to the introduction of context managers |
|