Scope guards style guide

Elias Batek (0xEAB) desisma at heidel.beer
Sun Mar 30 21:47:22 UTC 2025


*The D Style*[0] doesn’t specify how scope guards should be 
written AFAICT.

```
scope(exit) action;

scope (exit) action;

scope(exit)
     action;

scope (exit)
     action;
```


Currently, Phobos mixes all variants.

- `scope\(exit\).+\n`: 316 matches in 42 files
- `scope \(exit\).+\n`: 14 matches in 6 files
- `scope\(exit\)\n`: 38 matches in 12 files
- `scope \(exit\)\n`: 11 matches in 6 files

(Numbers might be slightly different for `~master`.)

**Is there any official recommendation on which style to use in 
which situation?**

The first variant seems to be preferred in practice.
Nevertheless, it differs from `version (…)` statements that have 
a space in between.

[0] https://dlang.org/dstyle.html


More information about the Digitalmars-d mailing list