D wrapper classes leak memory. Next steps?

eles via Digitalmars-d digitalmars-d at puremagic.com
Fri Oct 31 14:43:25 PDT 2014


On Friday, 31 October 2014 at 13:42:53 UTC, Ola Fosheim Grøstad 
wrote:
> On Friday, 31 October 2014 at 13:16:17 UTC, eles wrote:
>> Something that I read here:
>>
>> https://news.ycombinator.com/item?id=7650917
>>
>> My feeling too.
>>
>> If you need more owners for a resource, then explicitly ask 
>> for.
>
> Thank you for sharing, a very interesting discussion topic.

Just skimming over this:

http://dlang.org/const-faq.html#const-parameters

it would seem to make sense to make them all const by default, 
and one would have to specifically mark as mutable those that 
would be changed. The problems with this are:

     It would be a huge break from past D practice, and practice 
in C, C++, Java, C#, etc.

-- Actually, this is the sole reason, but the breakage would be 
far less that the breakage introduced by Rust & co. The two 
reasons that follow are almost hypocrisy to justify the fear in 
point 1.


     It would require a new keyword, say mutable.

-- Big deal. C++ has mutable too.

     And worst, it would make declarations inconsistent:

     void foo(int* p)
     {
         int* q;
         ...
     }

     p points to const, and q points to mutable. This kind of 
inconsistency leads to all sorts of mistakes. It also makes it 
very hard to write generic code that deals with types.

-- Why not make all pointer declarations as constant by default? 
Then, you explicitely ask for a mutable reference (hell, you 
could even limit the number of mutable references that could be 
asked for, if you want). Just reformulate to say:

"p points to const, and q points to const. This kind of 
consistency leads to all kind of great code. It also makes it 
very easy to write generic code that deals with types."


More information about the Digitalmars-d mailing list