"with" should be deprecated with extreme prejudice

Joel Lucsy jjlucsy at gmail.com
Tue May 19 07:16:48 PDT 2009


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
}

-- 
Joel Lucsy
"The dinosaurs became extinct because they didn't have a space program." 
-- Larry Niven



More information about the Digitalmars-d mailing list