D Beginner Trying Manual Memory Management
aldanor via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jan 12 14:07:13 PST 2015
On Monday, 12 January 2015 at 21:54:51 UTC, ketmar via
Digitalmars-d-learn wrote:
> On Mon, 12 Jan 2015 21:37:27 +0000
> aldanor via Digitalmars-d-learn
> <digitalmars-d-learn at puremagic.com>
> wrote:
>
>> On Monday, 12 January 2015 at 20:30:45 UTC, ketmar via
>> Digitalmars-d-learn wrote:
>> > it even has `RefCounted!`, but it doesn't play well with
>> > classes yet
>> > (AFAIR).
>> I wonder if it's possible to somehow make a version of
>> refcounted that would work with classes (even if
>> limited/restricted in some certain ways), or is it just
>> technically impossible because of reference semantics?
> it's hard. especially hard when you considering inheritance
> (which is
> not playing well with templates) and yes, ref semantics.
>
> on the other side i found myself rarely using classes at all. i
> mostly
> writing templates that checks if a passed "thing" has all the
> neccessary methods and properties in place and just using that.
> with D
> metaprogramming abilities (and `alias this` trick ;-)
> inheritance
> becomes not so important. and so classes too. sometimes i'm
> using
> structs with delegate fields to simulate some sort of "virtual
> methods"
> 'cause i tend to constantly forgetting about that `class`
> thingy. ;-)
>
> OOP is overrated. at least c++-like (should i say
> "simula-like"?)
> OOP. ;-)
I see, thanks! :) I've started liking structs more and more
recently as well and been pondering on how to convert a
class-based code that looks like this (only the base class has
any data):
class Base { T m_variable; }
class Common : Base { /* tons of methods; uses m_variable */ }
class Extra : Base { /* another ton of methods; uses m_variable
*/ }
class A : Extra, Common { ... }
class B : Common { ... }
class C : Extra { ... }
to refcounted structs with alias this but couldn't quite figure
out how to do it (other than use mixin templates...). Even if the
multiple alias this DIP was implemented, I don't think it would
help much here :/
More information about the Digitalmars-d-learn
mailing list