Suggestion: a shortcut for calling the base member function with unchanged parameters
Dawid Ciężarkiewicz
dawid.ciezarkiewicz at gmail.com
Fri Aug 25 05:56:06 PDT 2006
Kristian wrote:
> Actually there is redundancy in "super.f($)" also. That is the function
> name.
>
> For all functions you could write "super($)" (or something) to call the
> base function.
>
> class Derived : Base {
> this() {
> super($);
> m_val = 10;
> }
> this(int val) {
> super($);
> m_val = val;
> }
>
> void f(int index, float val1, float val2, bool isScalingUsed) {
> //do something
> ...
>
> super($);
> }
>
> int func(int x, int y, int length) {
> //do something
> ...
>
> return super($);
> }
> }
>
> I'm not sure that I like "$" in "super($)". Plain "super()" would be nice,
> but you cannot use it inside constructors (it calls "super.this()"). (Hmm,
> maybe "super(!)"...)
>
>
> On Mon, 21 Aug 2006 20:41:23 +0300, Kristian <kjkilpi at gmail.com> wrote:
>> Let we have the following two classes:
>>
>> class Base {
>> void f(int index, float val1, float val2, bool isScalingUsed) {...}
>> }
>>
>> class Derived : Base {
>> void f(int index, float val1, float val2, bool isScalingUsed) {
>> //do something
>> ...
>>
>> super.f(index, val1, val2, isScalingUsed);
>> }
>> }
>>
>> At the end of 'Derived.f()' we call the corresponding function of the
>> base class without modifing any of the parameters. How many times you
>> have done it? I have done it quite many times.
>>
>> The parameter list of 'super.f()' is redundant code.
>> You can make a typo or two when writing it. In addition, when the
>> parameter list of 'f()' is modified, or some of the paramters are
>> renamed, you have to change 'super.f(...)' also. It's tedious and you
>> can easily make an error, or you simply forget to do that.
>>
>> So, why not get rid of that redundant code?
>>
>> Let there be some kind of shortcut for it. For example:
>>
>> super.f($); //== 'super.f(index, val1, val2, isScalingUsed)'
>>
>> Naturally this kind of shortcutting should be possible with the
>> constructors also (i.e. "super($);").
-1
More information about the Digitalmars-d
mailing list