"with" should be deprecated with extreme prejudice

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun May 17 18:56:14 PDT 2009


Robert Fraser wrote:
> Jason House wrote:
>> 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
>>
>> How about we keep in D's tradition and outlaw shadowing instead? I use 
>> "with" rarely, but appreciate it when I do.
> 
> This. Just issue an error/warning if something in the with shadows 
> something outside. That way, if the struct/class/template/whatever 
> changes, affected code will be notified.

No warning, error!

This is a great idea Jason.

Andrei



More information about the Digitalmars-d mailing list