Wrong by Default
I&#x27;ve been so annoyed with people falsely equating defer and RAII that it didn&#x27;t occur to me this is yet another way it&#x27;s inferior!<p>The thing that usually comes to mind for me is that defer only works for local scope. RAII is more general because RAII objects can be put inside other objects that have different lifetimes. I can have an OpenFile inside a struct inside a reference counted smart pointer which will make it so that when the last user using that file disconnects the file is automatically closed. Defer can&#x27;t do that.