5 ms·
defer (/using/with) all require the programmer to remember, and write, O(use site) times, the code to release the resource. RAII destructors, on the other hand
by deathanatos 5y ago
defer (/using/with) all require the programmer to remember, and write, O(use site) times, the code to release the resource.
RAII destructors, on the other hand, do not permit the coder (at the use site of the type) to forget, as the destructor is invoked automatically when the variable goes out of scope.
In my time reviewing Python (also GC, "with" provides a similar functionality), this is a very common error.
- pjmlp 5y agoApparently you missed my go vet reference on purpose, just make all of us aware of it not being the same. Same applies to using on .NET, where forgetting to call using on an IDisposable type can trigger a compiler error, via Roslyn plugins. Also seem to be unaware how closure based RAII works on FP languages. RAII isn't triggered on heap allocated objects unless smart pointers are used everywhere. Python doesn't have a static analysis tool for with, nor does it support value types with stack allocation. Not all GC languages were born equal.
- nemetroid 5y ago> RAII isn't triggered on heap allocated objects unless smart pointers are used everywhere. It's triggered unless you have memory leaks.