A shorter alias for scope(exit) possible? a case for `defer`

Nick Treleaven nick at geany.org
Sat Aug 6 10:15:50 UTC 2022


On Saturday, 6 August 2022 at 00:16:56 UTC, ryuukk_ wrote:
> I'm not a RAII lover
>
> I like to manage manually manage resources and have fine 
> control over them

Vale has a feature where it won't let you forget to call a 
function to destroy user types marked as such when they go out of 
scope. So you call a named destructor, which can take arguments 
too:
https://verdagon.dev/blog/higher-raii-7drl

I'd like this in D. It doesn't replace scope(exit), but it 
guarantees you don't forget to do 'manual' cleanup.

> So i use `scope(exit)` a lot, however they can be a pain to 
> type, mostly due to the parenthesis

Personally I would use snippet completion in my editor (Geany). 
Might be called something else in other editors. So when I type 
`se` and press tab it would expand to `scope(exit)`. You can 
configure it to put a brace block after it if you want and have 
the cursor be inside it with appropriate indentation.


More information about the Digitalmars-d mailing list