3 ms·
It's still wrong by default. The correct pattern here is RAII, which requires no explicit cleanup code so there's no forgetting to use it.
by bitwize 4y ago
It's still wrong by default.
The correct pattern here is RAII, which requires no explicit cleanup code so there's no forgetting to use it.
- aliceryhl 4y agoThe article specifically talks about C, which does not have RAII.
- WalterBright 4y agoD does support RAII. But RAII has a problem: If you want transactions A and B to be both successful, or both are unwound, using RAII is a clumsy technique. It gets much worse if you need A, B and C to either all succeed or all fail. This article goes into detail: https://dlang.org/articles/exception-safe.html https://dlang.org/articles/exception-safe.html