braceless with statements
Steven Schveighoffer
schveiguy at gmail.com
Sat Nov 13 14:42:55 UTC 2021
On 11/13/21 5:43 AM, Ogi wrote:
> On Friday, 12 November 2021 at 15:33:38 UTC, Steven Schveighoffer wrote:
>> No, you are wanting to use the members of `s` many times, and don't
>> want to have to repeat `s.` all the time. This isn't a great example
>> because of the brevity. But imagine a long expression instead of the
>> single-letter variable.
>>
>> `with` already works as noted in the first case, the second case would
>> just be a way to write the same thing but without braces (and
>> indentation).
>
> I see, thanks.
>
> Can’t say I am a fan of this proposal. Are you in the same scope as a
> few hundred lines above? With braces and indentation, the answer is
> clear. Without them, you’ll have to look for `with` labels that don’t
> stand out visually at all.
I don't really understand the question. What is the confusion you are
having?
Consider the `scope(exit)` rewrite:
```d
{
someCode;
scope(exit) close(foo);
someCode;
}
```
This is equivalent to:
```d
{
someCode;
try { // new scope!
someCode;
} finally {
close(foo);
}
}
```
This introduces a new scope the same as a `with:` would introduce a new
scope (and actually is simpler). Have you had confusion about that
feature before? It makes perfect sense to me.
-Steve
More information about the Digitalmars-d
mailing list