Please add this
and super
to constructor parameters.
Old style:
struct Rectangle {
int x,y,width,height;
Color color;
this(int x, int y, int width, int height, Color color) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.color = color;
}
}
New style. Shorter. Less to type:
struct Rectangle {
int x,y,width,height;
Color color;
this(this.x, this.y, this.width, this.height, this.color) {}
}
Constructor initialization is annoying and often repeating.
Make it shorter. Nicer.
this
and super
can be directly supported in constructor parameters. It would save lots of typing.
The code:
module app;
class Vector2D {
float x, y;
this(int x, int y) {
this.x = x;
this.y = y;
}
}
class Vector3D : Vector2D {
float z;
this(int x, int y, int z) {
super(x,y);
this.z = z;
}
}
void main() {
auto v1 = new Vector2D(10,20);
}
could be shortened to:
module app;
class Vector2D {
float x, y;
this(this.x, this.y);
}
class Vector3D : Vector2D {
float z;
this(super.x, super.y, this.z);
}
void main() {
auto v1 = new Vector2D(10,20);
}
or ```d
module app;
class Vector2D {
float x, y;
this(this.x, this.y) {}
}
class Vector3D : Vector2D {
float z;
this(super.x, super.y, this.z) {}
}
void main() {
auto v1 = new Vector2D(10,20);
}