"with" should be deprecated with extreme prejudice

Christopher Wright dhasenan at gmail.com
Mon May 18 15:22:48 PDT 2009


Steven Schveighoffer wrote:
> On Mon, 18 May 2009 16:14:29 -0400, 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.
> 
> Had to look it up, never used it.
> 
> Not sure it's that terrible, it looks to be the equivalent in D of:
> 
> {
>   scope C = new C();
>   ...
> }
> 
> I suppose it's good in cases where you want to have somewhat manual 
> memory management.  Does seem poorly named though.

Or transactions, or locking, or similar things.

One of the interesting uses of it that I've seen is in Rhino Mocks:
using (Mocks.Ordered())
{
	everything in this block records expected calls where the order matters
}
but over here, order doesn't matter.



More information about the Digitalmars-d mailing list