"with" should be deprecated with extreme prejudice

grauzone none at example.net
Sun May 17 22:26:58 PDT 2009


Derek Parnell wrote:
> On Sun, 17 May 2009 19:33:35 -0500, 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;
>> }

I agree.

> I guess the reason for using with() is to avoid typing repetitive stuff.
> Would this work instead ...
> 
> 
>  int x, y;
>  with (p as "somevery.long.struct.or.class[17].name")
>  {
>       y += p.x;
>       ++p.x;
>  }
> 

You could as well use auto and a block without statement before it to 
set the scope. But that'd look kind of ugly. A block without statement 
looks like you forgot an if.

Here's another simple fix for with();

int x, y;
with (whatever)
{
       .y += x; //.y references this is whatever.y
       ++x;     //x references local scope
}



More information about the Digitalmars-d mailing list