The `with` construct is good, but it could be great

IGotD- nise at nise.com
Wed Jul 20 18:15:10 UTC 2022


On Wednesday, 20 July 2022 at 16:46:10 UTC, Quirin Schroll wrote:
>
> Contrary to others, I do not believe that `with` expressions 
> would be necessary. The main reason `with` expressions are 
> asked for is because `with` introduces scope.

One of the big usage of "with" in C# is that the destructor (on 
the class that is in the with expression) is guaranteed to be run 
when it leaves the scope. C# is similar to D that you don't know 
when the destructor is executed but the "with" statement makes it 
deterministic.

Does D need a "with" statement? I don't know and it also depends 
how the libraries are written. I'm personally not completely 
against introducing "with" in D. D has tried to follow Rust 
lately but I rather see that D follows C# as it is a better fit.


More information about the Digitalmars-d mailing list