On Monday, 5 August 2013 at 18:29:09 UTC, Dicebot wrote:
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.

Well I don't know much stuff about GC and internals and if you think it is not a good design concept, ok I'm fine with it. I don't "miss" C#'s using statement or IDisposable. I was just giving a suggestion that would be discussed and considered with the community.

At least this with(declaration) syntax might make it into the language. And probably use the more "strange" one, where you only give it an rvalue:
with(new Foo) {
    name = "Foo"; //same as temp.name
    calc(); //same as temp.calc()
writeln(); //and even maybe this to be translated to temp.writeln() and then to writeln(temp) ?
}

Well that was everything I had to say about with, using, and dispose. I'm glad that there was a discussion going.

Reply via email to