www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Suggestion: a shortcut for calling the base member function with unchanged parameters

reply Kristian <kjkilpi gmail.com> writes:
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 ba=
se  =

class without modifing any of the parameters. How many times you have do=
ne  =

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 rename=
d,  =

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($);  //=3D=3D 'super.f(index, val1, val2, isScalingUsed)'

Naturally this kind of shortcutting should be possible with the  =

constructors also (i.e. "super($);").
Aug 21 2006
parent reply Kristian <kjkilpi gmail.com> writes:
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 =3D 10;
      }
      this(int val) {
          super($);
          m_val =3D 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 nic=
e,  =

but you cannot use it inside constructors (it calls "super.this()"). (Hm=
m,  =

maybe "super(!)"...)


On Mon, 21 Aug 2006 20:41:23 +0300, Kristian <kjkilpi 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($);  //=3D=3D 'super.f(index, val1, val2, isScalingUsed)'=

 Naturally this kind of shortcutting should be possible with the  =

 constructors also (i.e. "super($);").

Aug 25 2006
parent Dawid =?UTF-8?B?Q2nEmcW8YXJraWV3aWN6?= <dawid.ciezarkiewicz gmail.com> writes:
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 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
Aug 25 2006