3 ms·
I'm not arguing against destructors, but this example is ultra contrived. Why would you defer cleaning up objects you are returning? That's no longer your res
by axaxs 5y ago
I'm not arguing against destructors, but this example is ultra contrived. Why would you defer cleaning up objects you are returning? That's no longer your responsibility.
Instead you'd return an object, and make it the callers responsibility to close it. Destruct all three in the close call.
It may not fit your mental model, and that's fine. But let's not pretend it's a serious hurdle.
- fauigerzigerk 5y ago>It may not fit your mental model... No, it's not a psychological problem. This is real complexity, and it's one of the most serious and widespread issues in software development. The key issue is that we often have rules that say: Whenever A happens then B must happen as well. It is absolutely critical that rules like this are expressed in exactly one place and that enforcement is opt-out not opt-in. Everything else is error prone and creates significant mental burden.