If D becomes a failure, what's the key reason, do you think?

Sean Kelly sean at f4.ca
Fri Jul 7 16:08:13 PDT 2006


David Medlock wrote:
> "c) Are passed allocated objects, which they are *NOT* allowed to 
> manipulate."
> 
> These are called interfaces, and are quite do-able in D.

This doesn't account for dynamic arrays, which are effectively passed by 
reference as well.
> 
> "d) Allocate and return objects/data that shouldn't be manipulated by 
> the user."
> 
> Such as what?  Nothing in D stops the two cases above.

     class C
     {
         char[] name() { return m_name; }
     private:
         char[] m_name;
     }

The convention is for the user to .dup the string if he intends to 
modify it, but this can be easy to forget, and tracking down a bug 
caused by this may be fairly time-consuming.  As far as I know, there's 
no way to expose a string reference with any degree of insurance that 
the data will not be altered.


Sean



More information about the Digitalmars-d mailing list