| Thread overview | |||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
August 15, 2008 Anonymous classes should pass through super ctors | ||||
|---|---|---|---|---|
| ||||
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(){}
};
| ||||
August 15, 2008 Re: Anonymous classes should pass through super ctors | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Frank Benoit | "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. :| | |||
August 15, 2008 Re: Anonymous classes should pass through super ctors | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | Reply to Jarrett,
> "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. :|
>
There needs to be a way to block that. That said, the current block-by-default is annoying.
| |||
August 18, 2008 Re: Anonymous classes should pass through super ctors | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | Jarrett Billingsley wrote: > "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. :| > > 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#D | |||
August 18, 2008 Re: Anonymous classes should pass through super ctors | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Bruno Medeiros | Bruno Medeiros schrieb:
> Jarrett Billingsley wrote:
>> "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. :|
>>
>
> 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.
>
Aren't anonymous classes a special case?
Because they are only instantiated once with exactly those arguments given in the declaration.
| |||
August 18, 2008 Re: Anonymous classes should pass through super ctors | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Frank Benoit | "Frank Benoit" wrote
> Bruno Medeiros schrieb:
>> Jarrett Billingsley wrote:
>>> "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. :|
>>>
>>
>> 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.
>>
>
> Aren't anonymous classes a special case?
> Because they are only instantiated once with exactly those arguments given
> in the declaration.
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.
-Steve
| |||
August 18, 2008 Re: Anonymous classes should pass through super ctors | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | Steven Schveighoffer schrieb:
> "Frank Benoit" wrote
>> Bruno Medeiros schrieb:
>>> Jarrett Billingsley wrote:
>>>> "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. :|
>>>>
>>> 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.
>>>
>> Aren't anonymous classes a special case?
>> Because they are only instantiated once with exactly those arguments given in the declaration.
>
> 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.
>
> -Steve
>
>
I 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.
| |||
August 18, 2008 Re: Anonymous classes should pass through super ctors | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Frank Benoit | Frank Benoit wrote: > Steven Schveighoffer schrieb: >> "Frank Benoit" wrote >>> Bruno Medeiros schrieb: >>>> Jarrett Billingsley wrote: >>>>> "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. :| >>>>> >>>> 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. >>>> >>> Aren't anonymous classes a special case? >>> Because they are only instantiated once with exactly those arguments given in the declaration. >> >> 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. >> >> -Steve >> > > I feel, that this is dangerous. > If there are such complicated ctors, they should be forwarded explicitly. But i have no real argument :) > 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 | |||
August 18, 2008 Re: Anonymous classes should pass through super ctors | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | 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;
| |||
August 18, 2008 Re: Anonymous classes should pass through super ctors | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Bruno Medeiros | 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 added to all constrictors (kind of like member variable initialization in c#)
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply