3 ms·
This construct gives you most of the power of C++ RAII without the overhead. But it leaves out the most useful part: in C++ releasing the resources is complete
by danieldk 11y ago
This construct gives you most of the power of C++ RAII without the overhead.
But it leaves out the most useful part: in C++ releasing the resources is completely implicit:
{
std::ifstream in(fn);
// Do something with 'in'
} // Released
while with Go defer, you have to call explicitly for the method that you want to call. If you forget this, you still have a resource leak.
Sure, it's an improvement over languages where you have to cover every possible scope exit, but it definitely doesn't give you 'most of the power' of C++ RAII.