digitalmars.D - Anonymous classes should pass through super ctors
- Frank Benoit (10/10) Aug 15 2008 Anonymous classes should pass through super ctors, if no ctor is given.
- Jarrett Billingsley (3/13) Aug 15 2008 All classes should pass through super ctors. :|
- BCS (3/20) Aug 15 2008 There needs to be a way to block that. That said, the current block-by-d...
- Bruno Medeiros (10/28) Aug 18 2008 Yes, if this was to be fixed/changed, it should be for all classes, not
- Frank Benoit (4/30) Aug 18 2008 Aren't anonymous classes a special case?
- Steven Schveighoffer (19/49) Aug 18 2008 Yeah, but if you're going to have auto-inheritance of constructors, why ...
- Frank Benoit (6/61) Aug 18 2008 I feel, that this is dangerous.
- Bruno Medeiros (10/72) Aug 18 2008 I don't see how this could be dangerous in any way whatsoever, if the
- BCS (4/12) Aug 18 2008 There needs to be an easy way to forbid one, several or all base constru...
- Steven Schveighoffer (12/26) Aug 18 2008 If you want to forbid all constructors, make a private constructor in th...
- BCS (7/40) Aug 18 2008 one option would be:
- Steven Schveighoffer (11/48) Aug 18 2008 Good, I think this would work with the current rules of overloading.
- BCS (2/23) Aug 18 2008 Ah, now I'm reading you correctly. That's exactly what I'm asking for. :...
- BCS (5/10) Aug 18 2008 // do all
- Sean Kelly (4/21) Aug 18 2008 Okay... I decided to dig up the proposal after all:
- Denis Koroskin (4/26) Aug 23 2008 FWIW, C++0x has this feature and we still don't :p
- Sean Kelly (6/18) Aug 18 2008 I'd argue that ctors should always be inherited if no ctor is defined,
Anonymous classes should pass through super ctors, if no ctor is given. class C { this( int i ){ .... } abstract void run(); // ... } auto c = new class(3) C { this( int a ){ super(a); } //<-- this line should not be necessary. void run(){} };
Aug 15 2008
"Frank Benoit" <keinfarbton googlemail.com> wrote in message news:g83v3k$n2u$1 digitalmars.com...Anonymous classes should pass through super ctors, if no ctor is given. class C { this( int i ){ .... } abstract void run(); // ... } auto c = new class(3) C { this( int a ){ super(a); } //<-- this line should not be necessary. void run(){} };All classes should pass through super ctors. :|
Aug 15 2008
Reply to Jarrett,"Frank Benoit" <keinfarbton googlemail.com> wrote in message news:g83v3k$n2u$1 digitalmars.com...There needs to be a way to block that. That said, the current block-by-default is annoying.Anonymous classes should pass through super ctors, if no ctor is given. class C { this( int i ){ .... } abstract void run(); // ... } auto c = new class(3) C { this( int a ){ super(a); } //<-- this line should not be necessary. void run(){} };All classes should pass through super ctors. :|
Aug 15 2008
Jarrett Billingsley wrote:"Frank Benoit" <keinfarbton googlemail.com> wrote in message news:g83v3k$n2u$1 digitalmars.com...Yes, if this was to be fixed/changed, it should be for all classes, not just anonymous ones. I remember this issue (the automatic inheritance of ctors) being discussed before. What were the opinions of the community? And Walters? (I don't recall myself) If there was something approaching consensus, it might be worth opening a bug ticket. -- Bruno Medeiros - Software Developer, MSc. in CS/E graduate http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#DAnonymous classes should pass through super ctors, if no ctor is given. class C { this( int i ){ .... } abstract void run(); // ... } auto c = new class(3) C { this( int a ){ super(a); } //<-- this line should not be necessary. void run(){} };All classes should pass through super ctors. :|
Aug 18 2008
Bruno Medeiros schrieb:Jarrett Billingsley wrote:Aren't anonymous classes a special case? Because they are only instantiated once with exactly those arguments given in the declaration."Frank Benoit" <keinfarbton googlemail.com> wrote in message news:g83v3k$n2u$1 digitalmars.com...Yes, if this was to be fixed/changed, it should be for all classes, not just anonymous ones. I remember this issue (the automatic inheritance of ctors) being discussed before. What were the opinions of the community? And Walters? (I don't recall myself) If there was something approaching consensus, it might be worth opening a bug ticket.Anonymous classes should pass through super ctors, if no ctor is given. class C { this( int i ){ .... } abstract void run(); // ... } auto c = new class(3) C { this( int a ){ super(a); } //<-- this line should not be necessary. void run(){} };All classes should pass through super ctors. :|
Aug 18 2008
"Frank Benoit" wroteBruno Medeiros schrieb:Yeah, but if you're going to have auto-inheritance of constructors, why not make it so I don't have to do this: class Base { this(int arg1, int arg2, char[] arg3, int arg4, float arg5) { ... } } class Derived : Base { this(int arg1, int arg2, char[] arg3, int arg4, float arg5) { super(arg1, arg2, arg3, arg4, arg5); } } This can get annoying for a large hierarchy where you always want to inherit the base class' intiailization methods. If we're going to get a way to do it for anonymous classes, I'd like it to be universal and consistent. -SteveJarrett Billingsley wrote:Aren't anonymous classes a special case? Because they are only instantiated once with exactly those arguments given in the declaration."Frank Benoit" <keinfarbton googlemail.com> wrote in message news:g83v3k$n2u$1 digitalmars.com...Yes, if this was to be fixed/changed, it should be for all classes, not just anonymous ones. I remember this issue (the automatic inheritance of ctors) being discussed before. What were the opinions of the community? And Walters? (I don't recall myself) If there was something approaching consensus, it might be worth opening a bug ticket.Anonymous classes should pass through super ctors, if no ctor is given. class C { this( int i ){ .... } abstract void run(); // ... } auto c = new class(3) C { this( int a ){ super(a); } //<-- this line should not be necessary. void run(){} };All classes should pass through super ctors. :|
Aug 18 2008
Steven Schveighoffer schrieb:"Frank Benoit" wroteI feel, that this is dangerous. If there are such complicated ctors, they should be forwarded explicitly. But i have no real argument :) In case of anonymous classes, the syntax should be compact. I think there are good reasons why Java does handle it this way.Bruno Medeiros schrieb:Yeah, but if you're going to have auto-inheritance of constructors, why not make it so I don't have to do this: class Base { this(int arg1, int arg2, char[] arg3, int arg4, float arg5) { ... } } class Derived : Base { this(int arg1, int arg2, char[] arg3, int arg4, float arg5) { super(arg1, arg2, arg3, arg4, arg5); } } This can get annoying for a large hierarchy where you always want to inherit the base class' intiailization methods. If we're going to get a way to do it for anonymous classes, I'd like it to be universal and consistent. -SteveJarrett Billingsley wrote:Aren't anonymous classes a special case? Because they are only instantiated once with exactly those arguments given in the declaration."Frank Benoit" <keinfarbton googlemail.com> wrote in message news:g83v3k$n2u$1 digitalmars.com...Yes, if this was to be fixed/changed, it should be for all classes, not just anonymous ones. I remember this issue (the automatic inheritance of ctors) being discussed before. What were the opinions of the community? And Walters? (I don't recall myself) If there was something approaching consensus, it might be worth opening a bug ticket.Anonymous classes should pass through super ctors, if no ctor is given. class C { this( int i ){ .... } abstract void run(); // ... } auto c = new class(3) C { this( int a ){ super(a); } //<-- this line should not be necessary. void run(){} };All classes should pass through super ctors. :|
Aug 18 2008
Frank Benoit wrote:Steven Schveighoffer schrieb:I don't see how this could be dangerous in any way whatsoever, if the ctor inheritance rules followed the same rules as method inheritance rules: * if you don't override or overload any ctor in the overload set, then the whole overload set is available in the child class. * if you do override or overload any ctor, well... follow the same rules as overriding/overloading a method. -- Bruno Medeiros - Software Developer, MSc. in CS/E graduate http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D"Frank Benoit" wroteI feel, that this is dangerous. If there are such complicated ctors, they should be forwarded explicitly. But i have no real argument :)Bruno Medeiros schrieb:Yeah, but if you're going to have auto-inheritance of constructors, why not make it so I don't have to do this: class Base { this(int arg1, int arg2, char[] arg3, int arg4, float arg5) { ... } } class Derived : Base { this(int arg1, int arg2, char[] arg3, int arg4, float arg5) { super(arg1, arg2, arg3, arg4, arg5); } } This can get annoying for a large hierarchy where you always want to inherit the base class' intiailization methods. If we're going to get a way to do it for anonymous classes, I'd like it to be universal and consistent. -SteveJarrett Billingsley wrote:Aren't anonymous classes a special case? Because they are only instantiated once with exactly those arguments given in the declaration."Frank Benoit" <keinfarbton googlemail.com> wrote in message news:g83v3k$n2u$1 digitalmars.com...Yes, if this was to be fixed/changed, it should be for all classes, not just anonymous ones. I remember this issue (the automatic inheritance of ctors) being discussed before. What were the opinions of the community? And Walters? (I don't recall myself) If there was something approaching consensus, it might be worth opening a bug ticket.Anonymous classes should pass through super ctors, if no ctor is given. class C { this( int i ){ .... } abstract void run(); // ... } auto c = new class(3) C { this( int a ){ super(a); } //<-- this line should not be necessary. void run(){} };All classes should pass through super ctors. :|
Aug 18 2008
Reply to Bruno,I don't see how this could be dangerous in any way whatsoever, if the ctor inheritance rules followed the same rules as method inheritance rules: * if you don't override or overload any ctor in the overload set, then the whole overload set is available in the child class. * if you do override or overload any ctor, well... follow the same rules as overriding/overloading a method.There needs to be an easy way to forbid one, several or all base constructors. And while were at it, it would be nice to add an auto constructor that is
Aug 18 2008
"BCS" wroteReply to Bruno,If you want to forbid all constructors, make a private constructor in the derived class. Due to the scope resolution rules of D, only the most derived class' counts, unless you alias the parent's. If you want to forbid one, then you have to forbid it the same way you do normal methods, implement all the ones you don't want to forbid. Yes, this is a pain, but it is consistent. If Walter wants to add a way to selectively alias in base methods, then use that way, but it needs to be consistent.I don't see how this could be dangerous in any way whatsoever, if the ctor inheritance rules followed the same rules as method inheritance rules: * if you don't override or overload any ctor in the overload set, then the whole overload set is available in the child class. * if you do override or overload any ctor, well... follow the same rules as overriding/overloading a method.There needs to be an easy way to forbid one, several or all base constructors.And while were at it, it would be nice to add an auto constructor that is added to all constrictors (kind of like member variable initialization inIt would be nice to be able to do this with runtime constructs, instead of being limited to compile-time ones. -Steve
Aug 18 2008
Reply to Steven,"BCS" wroteyupReply to Bruno,If you want to forbid all constructors, make a private constructor in the derived class. Due to the scope resolution rules of D, only the most derived class' counts, unless you alias the parent's.I don't see how this could be dangerous in any way whatsoever, if the ctor inheritance rules followed the same rules as method inheritance rules: * if you don't override or overload any ctor in the overload set, then the whole overload set is available in the child class. * if you do override or overload any ctor, well... follow the same rules as overriding/overloading a method.There needs to be an easy way to forbid one, several or all base constructors.If you want to forbid one, then you have to forbid it the same way you do normal methods, implement all the ones you don't want to forbid.one option would be: private this(/* the signiture *){assert(false);} // forbid this alias this this; // get everything elseI'm not following...And while were at it, it would be nice to add an auto constructor that is added to all constrictors (kind of like member variableIt would be nice to be able to do this with runtime constructs, instead of being limited to compile-time ones.-Steve
Aug 18 2008
"BCS" <ao pathlink.com> wrote in message news:55391cb330b528cacf3c1a094fc2 news.digitalmars.com...Reply to Steven,Good, I think this would work with the current rules of overloading."BCS" wroteyupReply to Bruno,If you want to forbid all constructors, make a private constructor in the derived class. Due to the scope resolution rules of D, only the most derived class' counts, unless you alias the parent's.I don't see how this could be dangerous in any way whatsoever, if the ctor inheritance rules followed the same rules as method inheritance rules: * if you don't override or overload any ctor in the overload set, then the whole overload set is available in the child class. * if you do override or overload any ctor, well... follow the same rules as overriding/overloading a method.There needs to be an easy way to forbid one, several or all base constructors.If you want to forbid one, then you have to forbid it the same way you do normal methods, implement all the ones you don't want to forbid.one option would be: private this(/* the signiture *){assert(false);} // forbid this alias this this; // get everything elsei.e. you can already do this today: class X { int blah = 5; } But it has to be a compile-time constant. It would be nice if you could use a runtime evaluated value. -SteveI'm not following...And while were at it, it would be nice to add an auto constructor that is added to all constrictors (kind of like member variableIt would be nice to be able to do this with runtime constructs, instead of being limited to compile-time ones.
Aug 18 2008
Reply to Steven,Ah, now I'm reading you correctly. That's exactly what I'm asking for. :)i.e. you can already do this today: class X { int blah = 5; } But it has to be a compile-time constant. It would be nice if you could use a runtime evaluated value. -SteveI'm not following...And while were at it, it would be nice to add an auto constructor that is added to all constrictors (kind of like member variableIt would be nice to be able to do this with runtime constructs, instead of being limited to compile-time ones.
Aug 18 2008
Reply to Steven,If we're going to get a way to do it for anonymous classes, I'd like it to be universal and consistent. -Steve// do all alias this this; // do just this one alias this(int, char[]) this;
Aug 18 2008
Bruno Medeiros wrote:Jarrett Billingsley wrote:Okay... I decided to dig up the proposal after all: http://www.digitalmars.com/d/archives/digitalmars/D/Inheriting_constructors_54088.html Sean"Frank Benoit" <keinfarbton googlemail.com> wrote in message news:g83v3k$n2u$1 digitalmars.com...Anonymous classes should pass through super ctors, if no ctor is given. class C { this( int i ){ .... } abstract void run(); // ... } auto c = new class(3) C { this( int a ){ super(a); } //<-- this line should not be necessary. void run(){} };All classes should pass through super ctors. :|
Aug 18 2008
On Mon, 18 Aug 2008 23:13:42 +0400, Sean Kelly <sean invisibleduck.org> wrote:Bruno Medeiros wrote:FWIW, C++0x has this feature and we still don't :p http://en.wikipedia.org/wiki/C++0x#Object_construction_improvementJarrett Billingsley wrote:Okay... I decided to dig up the proposal after all: http://www.digitalmars.com/d/archives/digitalmars/D/Inheriting_constructors_54088.html Sean"Frank Benoit" <keinfarbton googlemail.com> wrote in message news:g83v3k$n2u$1 digitalmars.com...Anonymous classes should pass through super ctors, if no ctor is given. class C { this( int i ){ .... } abstract void run(); // ... } auto c = new class(3) C { this( int a ){ super(a); } //<-- this line should not be necessary. void run(){} };All classes should pass through super ctors. :|
Aug 23 2008
Frank Benoit wrote:Anonymous classes should pass through super ctors, if no ctor is given. class C { this( int i ){ .... } abstract void run(); // ... } auto c = new class(3) C { this( int a ){ super(a); } //<-- this line should not be necessary. void run(){} };I'd argue that ctors should always be inherited if no ctor is defined, much like the regular function lookup rules for classes. In fact, I posted a proposal regarding this maybe a year ago, but I'm too lazy to go looking for it now. Sean
Aug 18 2008