mutable constant?

Ali Çehreli acehreli at yahoo.com
Tue Jun 25 16:39:43 PDT 2013


With apologies, I have unrelated comments to make.

On 06/25/2013 03:07 PM, Namespace wrote:

 >      this(T x, T y) {
 >          this.x = x;
 >          this.y = y;
 >
 >          points ~= &this._point;

I have seen similar designs in the past where constructors had 
side-effects such as registering the object in a global state. (Exactly 
what the last line is doing above.)

It has almost always been cause of trouble. It is better to register an 
object from the outside after constructing it.

Sometimes I had attempted to remove seemingly unused objects only to be 
reminded by a comment that it should not be:

     // Do not remove! Registers itself in the points array
     auto p = Point();

 >      @property
 >      inout(Point)* ptr() inout {
 >          points[this.id].x = cast(int) this.x;
 >          points[this.id].y = cast(int) this.y;

That looks questionable as well: ptr() looks like an accessor but it 
makes changes to a global state.

Ali



More information about the Digitalmars-d-learn mailing list