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

ryuukk_ ryuukk.dev at gmail.com
Sat Aug 6 00:16:56 UTC 2022


I'm not a RAII lover

I like to manage manually manage resources and have fine control 
over them

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

The first thing i tried was an alias, but unfortunately that's 
not possible

```
src\states\gameplay_r.d(35,20): Error: basic type expected, not 
`(`
src\states\gameplay_r.d(35,20): Error: function declaration 
without return type. (Note that constructors are always named 
`this`)
src\states\gameplay_r.d(35,26): Deprecation: storage class 
`scope` has no effect in type aliases
```

And even if possible, i'm still not a fan of having to import a 
module everywhere i'd need to type it

What do you guys think? `defer` seems to be a the choice in most 
of the languages, could it be a good alias for `scope(exit)` in 
D? if no what's your solution?






More information about the Digitalmars-d mailing list