3 ms·
Go has a garbage collector. RAII is only viable in languages where destruction is predictable, like C++ or PHP.
by mratzloff 9y ago
Go has a garbage collector. RAII is only viable in languages where destruction is predictable, like C++ or PHP.
- int_19h 9y ago"defer" is effectively used for predictable destruction in Go, and a more automated RAII scheme could be used in its place. C++/CLI is a language that targets a garbage-collected runtime, yet has full-fledged RAII semantics (they're mapped to CLR Dispose pattern).
- mratzloff 9y agoOh, I totally forgot about C++/CLI! You're absolutely right; that's my mistake. I do agree that RAII is preferable.
- pcwalton 9y agoThe tracing GC certainly complicates things, but you can make it work with a "scope" keyword like in D.
- pjmlp 9y agoPHP also has a garbage collector. Swift and D also have garbage collectors and support RAII. And since I already see it coming, reference counting is a garbage collection implementation algorithm in computer science literature.