With statement become like C#'s using?

Dicebot public at dicebot.lv
Mon Aug 5 11:29:07 PDT 2013


On Monday, 5 August 2013 at 17:45:25 UTC, Bosak wrote:
> You say that D's destroy is not like C#'s IDisposable.Then why 
> doesn't D then declare that kind of interface:
> interface Disposable {
>     void dispose();
> }

It _is_ similar but not exact match. 2 key differences:
1) destroy works on variety of types, not only classes
2) it puts the object into some invalid state
But you can still use class destructor instead of `dispose()` 
method.

But destroy() is considered a power tool that should be used only 
when absolutely needed. The very necessity to deterministically 
call some method opposes the concept of garbage collection - it 
is a sign of bad design and clear indicator that one should do a 
proper RAII here. I really think D approach here is much cleaner 
than C# one.


More information about the Digitalmars-d mailing list