Why D const is annoying
    Mehrdad 
    wfunction at hotmail.com
       
    Tue May  1 18:55:03 PDT 2012
    
    
  
Let's say you have this hypothetical piece of code:
interface IConnection { string send(string data); }
class Student
{
    private string id;
    private string cachedName;
    private IConnection conn;
    public this(string id) { this.id = id; this.conn = ...; }
    public @property string name() const
    {
        if (!cachedName)
        { cachedName = conn.send("get_name: " ~ id); }
        return cachedName;
    }
}
void main()
{
    auto student = new immutable(Student)("142341234");
    writeln(student.name);
}
Notice that there are two const-related issues in the code that are 
literally *unsolvable* (unless you avoid const/immutable entirely, or unless 
you cast() -- but then your entire code would be filled with dangerous const 
casts...).
How does D2 plan to address these issues in the 'ideal' implementation? 
    
    
More information about the Digitalmars-d
mailing list