D 2015/2016 Vision?

bitwise via Digitalmars-d digitalmars-d at puremagic.com
Tue Oct 6 13:43:40 PDT 2015


On Tuesday, 6 October 2015 at 18:43:42 UTC, Jonathan M Davis 
wrote:
> On Tuesday, 6 October 2015 at 18:10:42 UTC, bitwise wrote:
>> On Tuesday, 6 October 2015 at 17:20:39 UTC, Jonathan M Davis 
>> wrote:
>> I'm not sure what else I can say. The example I posted says it 
>> all, and it can't be done properly in D (or C#, but why lower 
>> the bar because of their mistakes? ;)
>
> It's a side effect of having the lifetime of an object managed 
> by the GC. There's no way around that except to use something 
> else like manual memory management or reference counting.

You are literally repeating what I just said in different words.

> in D, it's a good reason to use structs to manage resources 
> like that, and since most objects really have no need of 
> inheritance and have no business being classes, it's usually 
> fine.

This is an opinion.

I want polymorphism AND deterministic destruction, and the least 
you could do is just admit that it's a downside to D not having 
it, instead of trying to tell me that everything I know is wrong..

> But in the cases where you do have to use a class, it can get 
> annoying.

YES, its does, and it's not just an odd case here and there..

> You simply do not rely on the GC or the destruction of the 
> object to free system resources. You manually call a function 
> on the object to free those resources when you're done with it.

I'm sorry, but I almost can't believe you're saying this.

So, you're saying you want me to just revert back to manual 
resource management and accept that huge resources like textures 
and such may just leak if someone doesn't use them right? or 
throws an exception? in a language like D that is supposed to be 
safe?

> In the case of C#, they have a construct to help with it that 
> (IIRC) is something like
>
> using(myObj)
> {
> } // myObj.dispose() is called when exiting this scope

For the THIRD time, I'll post my example:

class Texture { }
class Texture2D : Texture {
     this() { /* load texture... */ }
     ~this { /* free texture */ }     // OOPS, when, if ever, will 
this be called?
}

Now, does this really seem like a realistic use case to you?

using(Texture tex = new Texture2D) {
     // ...
}

> Having the option to have properly ref-counted classes in 
> addition to classes managed by the GC would definitely be an 
> improvement, and I expect that we'll get there at some point, 
> but there _are_ ways to deal with the problem in the interim, 
> even if it's not ideal.

This brings me right back to where I started this, which was 
asking about this situation.

_Is_ it just the interim? Will DIP74 actually ever be 
implemented? if so, when?

> In most cases though, just don't use classes. In most cases, 
> inheritance is a horrible way to write programs anyway,

Opinion.

> I suspect that far too many folks new to D end up using classes 
> instead of structs just because they're used to
> using classes in C++ or Java or whatever.

I use classes for polymorphism, and although I can't speak for 
everyone else, I doubt I'm the only one.

       Bit



More information about the Digitalmars-d mailing list