"with" should be deprecated with extreme prejudice
Lester L. Martin II
lestermartin92 at gmail.com
Sun May 17 18:41:56 PDT 2009
Andrei Alexandrescu Wrote:
> I think "with" is a very dangerous feature due to the way it hides
> symbols. It essentially makes the feeblest attempt at modular reasoning
> utterly impossible:
>
> int x, y;
> with (whatever)
> {
> y += x;
> ++x;
> }
>
> What can be said about such code? Nothing. If whatever has or will ever
> have fields x or y or both, the names will bind to them; otherwise,
> they'll bind to the locals. Non-local code dependency at its finest.
>
> Maintenance of any type that is being used with "with" becomes a very
> dangerous proposition because it can silently change meaning of code.
>
> I therefore submit that "with" is an extremely dangerous feature and
> should be removed from the language. What say you?
>
>
> Andrei
I agree with dsimcha.
When you do this, do you consider how much code written in D actually uses this. I find it very, very useful. It's deprecation and further removal would take a huge hit on my code. What I would propose instead is that you can't modify variables outside of the scope, but only those that reside in the type whatever. In this case, you can't possibly change the variables outside of the with(whatever) scope, but you can modify anything that is in the type whatever, because this is how I believe it is mainly used. Deprecation of this feature should never happen. I doubt I and dsimcha will be the only unhappy coders.
Lester L. Martin II
More information about the Digitalmars-d
mailing list