|
|
|
|
|
by tibordp
1391 days ago
|
|
Scoped destruction is awesome in general, and I agree that it is superior to defer. I think one case where defer might be nicer is for things that are not strictly memory, e.g. inserting some element into a container and removing it after the function finishes (or setting a flag and restoring it). This can be done with a guard object in RAII languages, but it's a bit unintuitive. Defer makes it very clear what is going on. |
|
Some syntactic sugar, like Python’s “with” should help with that, shouldn’t it?