|
|
|
|
|
by kbr-
421 days ago
|
|
> It’s a simple keyword, but it singlehandedly eliminates the need for any kind of RAII. What if you want to put a resource object (which needs a cleanup on destruction) into a vector then give up ownership of the vector to someone? I write code in go now after moving from C++ and God do I miss destructors. Saying that defer eliminates need for RAII triggers me so much |
|
I do not subscribe to that idea because with RAII you can still have batched drops, the only difference between the two defaults is that with defer the failure mode is leaks, while with RAII the failure mode is more code than you'd otherwise would have.