"with" should be deprecated with extreme prejudice
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Mon May 18 13:36:35 PDT 2009
Bill Baxter wrote:
> On Mon, May 18, 2009 at 1:14 PM, Andrei Alexandrescu
> <SeeWebsiteForEmail at erdani.org> wrote:
>> Nick Sabalausky wrote:
>>> "Leandro Lucarella" <llucax at gmail.com> wrote in message
>>> news:20090518141908.GB9277 at burns.springfield.home...
>>>> bearophile, el 18 de mayo a las 04:33 me escribiste:
>>>>> Andrei, I agree that "with" is dangerous when it shadows outer names
>>>>> (Python designers have not added a "with" because of this).
>>>> They did, but with different semantics =)
>>>> It's used for RAII (I guess you already know that, but maybe other people
>>>> don't).
>>>>
>>> You mean like C#'s "using"?
>> What a God awful feature. Honestly, "what were they sinking about?" People
>> who explained that C# is cool - please explain this one.
>
> Looks like
>
> using(Foo x = new Foo()) {
> // do stuff
> }
>
> It's basically equiv of
>
> {
> auto x = new Foo();
> scope(exit) foo.Dispose;
> // do stuff
> }
>
> So it saves a little typing but is capable of less. scope(exit) is way cooler.
> Python has a similar feature to C#'s using. In Python it's called
> "with". http://effbot.org/zone/python-with-statement.htm
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.
Andrei
More information about the Digitalmars-d
mailing list