"with" should be deprecated with extreme prejudice

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue May 19 08:46:43 PDT 2009


Joel Lucsy wrote:
> Andrei Alexandrescu wrote:
>>> <SeeWebsiteForEmail at erdani.org> wrote:
>>> using(Foo x = new Foo()) {
>>>      // do stuff
>>> }
>>>
>>> It's basically equiv of
>>>
>>> {
>>>     auto x = new Foo();
>>>     scope(exit) foo.Dispose;
>>>     // do stuff
>>> }
>> That's not an "equiv of". It's "completely missing the point of". Each 
>> "using" costs one new scope and one level of indentation which makes 
>> it non-scalable. Indentation is *expensive*. I think the C# folks 
>> missed the class when try/catch/finally showed with extensive examples 
>> just how expensive extra indentation is.
> 
> You can mitigate this somewhat by realizing that multiple usings can be 
> wrapped into only one indentation level. Like:
> 
> using (Bar bar = new Bar())
> using (Foo foo = new Foo())
> using (Jim jim = new Jim())
> {
>     //do something
> }
> 

Thanks, that's a good point.

(It's a limited option, though. My code uses scope() statements to do 
things transactionally (e.g. search Phobos for scope) and the pattern 
sometimes is to do some work, plant a scope(), then do some work, plan 
another, etc. This would be difficult with using().)

Andrei



More information about the Digitalmars-d mailing list