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

max haughton maxhaton at gmail.com
Thu Jul 21 01:41:03 UTC 2022


On Wednesday, 20 July 2022 at 16:46:10 UTC, Quirin Schroll wrote:
> The [`with` 
> statement](https://dlang.org/spec/statement.html#with-statement) is a good feature. However, a lot of people including me believe that it lacks potential to be great.
>
> It introduces scope and cannot be used in a declarative scope.
>
> It’s shortcomings are surprisingly similar to C++’s `if 
> constexpr` that Andrei in [*Design by 
> Introspection*](https://www.youtube.com/watch?v=k31wZafAMhk&t=1712) considered to be a “fatal mistake”.
>
> Up for discussion, I’d even suggest a no-brace form for `with` 
> *declarations:*
> * `with Symbol:` or `with(Symbol):` (like attributes)
> * `with Symbol;` (like `import`)
>
> That implemented, `with` would be a great feature.
>
> 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.

The main reason why with expressions are desired is so they can 
be used in expressions, adding a form that does not introduce a 
scope does not change this.


More information about the Digitalmars-d mailing list