On Monday, 6 October 2014 at 06:23:42 UTC, eles wrote:
On Monday, 6 October 2014 at 03:48:49 UTC, Andrei Alexandrescu wrote:
On 10/5/14, 3:08 PM, eles wrote:
On Sunday, 5 October 2014 at 14:55:38 UTC, Dicebot wrote:

The main distinction between structs and classes in D is the former are monomorphic value types and the later are polymorphic reference types. -- Andrei

Why hack them with scoped? The need exists, since you provide a hack for it.

Reference classes in C++ are polymorphic & reference, but their destructor/disposer gets called.

There is a delete that triggers that or a smart pointer. I don't care if the delete or the destructor really frees the memory, but I would like it to get called, to release other resources that the object might have locked and to mark the object as "invalid". Later access to it shall triger an exception: "invalidObject".

Call it dispose if you like, because delete is too much like freeing memory.

Is there an intermediate type between structs and classes?

Form that page again:

"I have found (dislcaimer: this is my experience, your mileage will vary) that because 90% of the time you don't need to worry about releasing a resource in C#, it is easy to forget to do a "using" the remaining 10%. In C++ you always need to worry about it, which makes it real easy to remember that when obtaining a resource make sure you have taken care of its release as well. (In essence, make sure it is stored in something whose destructor will free it). I have found this pattern a lot harder to follow in C# than in C++.

Having said all that, there is a lot to like about .NET and C# as well. I just personally find that the whole "garbage collector saves you" aspect that is pitched in every intro to the language I have encountered more of a trap than a salvation."

Reply via email to