Topic: Leaving out parameters


Author: schuenem@Informatik.TU-Muenchen.DE (Ulf Schuenemann)
Date: 17 Aug 1994 17:06:04 GMT
Raw View
In article <CtuqI3.EJx@cwi.nl>, olaf@cwi.nl (Olaf Weber) writes:
|> In article <CtpnFG.GDC@murdoch.acc.Virginia.EDU>, gs4t@kelvin.seas.Virginia.EDU (Gnanasekaran  Swaminathan) writes:
|>
|> > clamage@taumet.Eng.Sun.COM (Steve Clamage) writes:
|> > : lmb@pointer.han.de (Lars Marowsky-Bree) writes:
|> > : >int Test(int a = 1, int b = 2, int c = 3);
|> > : >....
|> > : >Test(2,,5);  //invokes Test(2,2,5)
|>
|> > : It is not allowed. There is no technical reason, but it was judged too
|> > : error-prone. For example, if your finger slips and you type an extra
|> > : comma or omit one, you might get a valid call to the wrong version of
|> > : an overloaded function. With the actual language rules, you are likely to
|> > : get an error message.
|>
|> > ...
|>
|> ... Personally, I
|> think it is an abomination.  Why no reuse `default'?
|>  Test(2, default, 5);
|> This looks much better, IMHO.  (Note that `default' is used to avoid
|> using the "magic number" 2 as the second parameter, not to save
|> keystrokes.)
|>
|> -- Olaf Weber

Considering this idea I would even think that being FORCED to use 'default'
instead of being able to leave out arguments from the end (when default
parameters are given) could have some advantages:
a) there is no reason any more to arange parameters, that the
   least important are at the end,
b) it makes looking for overloaded functions (with different number of
   parmeters) easier (*),
c) the possibilty of leaving out trailing arguments could still
   be achieved with ordinary inline-function-overloading.

(*) Often there is the complaint that writing the C++-compiler gets
more complex with every new feature. When I try to imagine how it
works, 'default' would be easier to implement than 'leaving-out-from-the-end':

1. You know the name of the called function and the number of arguments.
2. If there is a 'default' argument you look up the symboltable for
   functions (conforming 1.) with a defaultvalue for this parameter.
3. If there are more than one functions matching 2. it is an ambiguity,
   else use the function found, replacing all 'default' by the given
   defaultvalue.

Please correct me if I'm wrong.

Just some further consiferations (brain-storming):
The current default-parameters animates programers to bad coding-style
(see a), and is not flexible enough (see repeated discussions about
f(1,,2)).
What about REPLACING the current leaving-out-trailing-params by using
'default'?
- This would break a lot of code.
+ It would rather be easier than more difficult to implement.

Constantly (calling for) adding NEW features to a language
makes it surely more and more complex. One way to work against this
is to drop old unnecessary features. E.g. old features get unnecessary
when the are/can be replaced by a (hopefully better, more general,
more orthogonal) feature. And C++ has a level of complexity where
it is necessary to also consider this.


Ulf Schuenemann

PS: this is my personal opion; this is not a proposal; I'm just trying
to brain-storm some idea; my aim is to improve C++; I will continue to use
C++ nevertheless; I will continue to exlain the old and the newly added
features to other people regardless of their aversions against complexity
and unorthogonalities of C++; and I will continue to try to explain them
why it is worth learning C++.
--------------------------------------------------------------------
Ulf Sch   nemann
Institut f   r Informatik, Technische Universit   t M   nchen.
email: schuenem@informatik.tu-muenchen.de





Author: olaf@cwi.nl (Olaf Weber)
Date: Mon, 1 Aug 1994 10:29:56 GMT
Raw View
In article <CtpnFG.GDC@murdoch.acc.Virginia.EDU>, gs4t@kelvin.seas.Virginia.EDU (Gnanasekaran  Swaminathan) writes:

> clamage@taumet.Eng.Sun.COM (Steve Clamage) writes:
> : lmb@pointer.han.de (Lars Marowsky-Bree) writes:
> : >int Test(int a = 1, int b = 2, int c = 3);
> : >....
> : >Test(2,,5);  //invokes Test(2,2,5)

> : It is not allowed. There is no technical reason, but it was judged too
> : error-prone. For example, if your finger slips and you type an extra
> : comma or omit one, you might get a valid call to the wrong version of
> : an overloaded function. With the actual language rules, you are likely to
> : get an error message.

> How about allowing
>  Test(2,void,5);
> There is a prior art in Mentor Graphics's AMPLE script language
> which allows both Test(2,,5) and Test(2,void,5).

You might also consider the use of `void' in function prototypes to
denote "takes no arguments" as a form of prior art.  Personally, I
think it is an abomination.  Why no reuse `default'?
 Test(2, default, 5);
This looks much better, IMHO.  (Note that `default' is used to avoid
using the "magic number" 2 as the second parameter, not to save
keystrokes.)

-- Olaf Weber




Author: gs4t@kelvin.seas.Virginia.EDU (Gnanasekaran Swaminathan)
Date: Fri, 29 Jul 1994 16:35:40 GMT
Raw View
clamage@taumet.Eng.Sun.COM (Steve Clamage) writes:
: lmb@pointer.han.de (Lars Marowsky-Bree) writes:
: >int Test(int a = 1, int b = 2, int c = 3);
: >....
: >Test(2,,5);  //invokes Test(2,2,5)

: It is not allowed. There is no technical reason, but it was judged too
: error-prone. For example, if your finger slips and you type an extra
: comma or omit one, you might get a valid call to the wrong version of
: an overloaded function. With the actual language rules, you are likely to
: get an error message.

How about allowing
 Test(2,void,5);
There is a prior art in Mentor Graphics's AMPLE script language
which allows both Test(2,,5) and Test(2,void,5).

-Sekar




Author: clamage@taumet.Eng.Sun.COM (Steve Clamage)
Date: 22 Jul 1994 18:01:06 GMT
Raw View
In article 5TGiAySeKRB@pointer.han.de, lmb@pointer.han.de (Lars Marowsky-Bree) writes:
>
>I would like to know if the following is legal:
>
>int Test(int a = 1, int b = 2, int c = 3);
>....
>Test(2,,5);  //invokes Test(2,2,5)
>....
>
>Why can't this be done?  Or can it?  (sorry, no ARM right here,  but
>I don't remember seeing anything like this in it)

It is not allowed. There is no technical reason, but it was judged too
error-prone. For example, if your finger slips and you type an extra
comma or omit one, you might get a valid call to the wrong version of
an overloaded function. With the actual language rules, you are likely to
get an error message.

---
Steve Clamage, stephen.clamage@eng.sun.com





Author: lmb@pointer.han.de (Lars Marowsky-Bree)
Date: 21 Jul 1994 13:42:00 +0200
Raw View
I would like to know if the following is legal:


int Test(int a = 1, int b = 2, int c = 3)
{
}

...
Test(2,,5);  //invokes Test(2,2,5)
...

Why can't this be done?  Or can it?  (sorry, no ARM right here,  but
I don't remember seeing anything like this in it)

PS: Sorry for my english,  but  I  think you understand what I mean.
(Hopefully;)

--
Lars Marowsky-Bree   Voice: +49-571-63663  PGP-key via return receipt
VirNet: @9:492/7158 Fido: @2:2449/620.16 InterNet: lmb@pointer.han.de
PGP fingerprint:     CF FC 3A F0 86 F1 D3 EB  79 8A CF 75 4F 4C 81 DF