Topic: Why do default arguments have to be at the end?
Author: rvloon@motif.hacktic.nl (Ronald van Loon)
Date: 6 Jun 1994 22:49:10 +0200 Raw View
haydens@wayback.atc.ll.mit.edu (Hayden Schultz x3685 ) writes:
|">>>>> "Bob" == Bob Affrunti <affrunti@orion.oac.uci.edu> writes:
|"Bob> Why couldn't you have something like:
|"Bob> x.afunction( ,2,3,4 ); x.afrunction( ,2,,4 );
|"Well, for one thing there is an operator,(). So what would the above
|"syntax mean? Trouble for both the programmer and the compiler
|"writer. I think that anyone who writes code like afunction(a,(b,c),c)
|"should be taken out and shot, but that's valid C++ (and C) code, which
|"would be broken or very difficult to interpret. Plus, it would be one
|"more break with C syntax for no real gain in functionality.
On the other hand, there is the `default' keyword - why not write
function-calls like `f(default,default,24)' ? That way, the programmer makes his
intention clear ("I only want to specify a different third argument to this
function") without having to resort to finding out what the current defaults
actually are.
It doesn't introduce ambiguity, because a single colon `:' is not a valid
thing to pass to a function, so one can distinguish between `default:' and
`default' without adding additional complexity to the language.
Of course, this is all very hypothetical if the committee isn't willing to
consider the possibility of defaults in other places, but it would be nice to
be able to specify a more natural order of arguments, instead of having to
rearrange them everytime because of `handy defaults'.
Just a thought.
--
Ronald van Loon \ S-Mail: St. Janskerkhof 18 / Even when you're
- Motif++ Maintainer \ 3811 HW Amersfoort / on the right track
- Columnist C++ Report \ The Netherlands / you'll get run over
(rvloon@motif.hacktic.nl) \ Phone: +31 33 758 293 / if you just sit there
Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Mon, 6 Jun 1994 17:02:06 GMT Raw View
In article <affrunti.770665780@orion.oac.uci.edu> affrunti@orion.oac.uci.edu (Bob Affrunti) writes:
>I have a question for the guys writing the c++ standard.
>
>Why do default arguments have to follow the required arguments?
>
See ARM p142, 8.2.6. Bjarne considered and rejected the idea,
I guess the committee doesnt want to argue with such a "style"
decision. Its not as if serious functionality is lost: there
are advantages and disadvantages and without a strong argument
to change things the status quo just remains.
[Other decisions like using <> for templates have serious
disadvantages for parsers and that one has been discussed,
but a change would break too much code]
--
JOHN (MAX) SKALLER, INTERNET:maxtal@suphys.physics.su.oz.au
Maxtal Pty Ltd, CSERVE:10236.1703
6 MacKay St ASHFIELD, Mem: SA IT/9/22,SC22/WG21
NSW 2131, AUSTRALIA
Author: affrunti@orion.oac.uci.edu (Bob Affrunti)
Date: 3 Jun 94 17:49:40 GMT Raw View
I have a question for the guys writing the c++ standard.
Why do default arguments have to follow the required arguments?
Why couldn't you have something like:
class Mine
{
public:
int aFunction( int arg1=1, int arg2, int arg3=1, int arg4 );
};
where it could be called by something like:
main()
{
Mine x;
x.afunction( 1,2,3,4 );
x.afunction( ,2,3,4 );
x.afrunction( ,2,,4 );
}
etc.
I am sure that it has something to do with implementation and
figuring out which function to call if they are overloaded, but
I have thought about it and can't see no difference between this
style and the style where all the default arguments were at the end!?!
Want to know something neat about this? It could be implemented and
not break any existing code! I know this is a very important consideration
for any change to the language.
Please think about it.
Author: pjl@graceland.att.com (Paul J. Lucas)
Date: Fri, 3 Jun 1994 18:37:50 GMT Raw View
In <affrunti.770665780@orion.oac.uci.edu> affrunti@orion.oac.uci.edu (Bob Affrunti) writes:
>Why do default arguments have to follow the required arguments?
>Why couldn't you have something like:
>main() {
>x.afunction( 1,2,3,4 );
>x.afunction( ,2,3,4 );
>x.afrunction( ,2,,4 );
>}
According to the ARM, it's because that's too subtle.
>I am sure that it has something to do with implementation and
>figuring out which function to call if they are overloaded, but
>I have thought about it and can't see no difference between this
>style and the style where all the default arguments were at the end!?!
It's not a technical problem. Just because something`n can be
done doesn't mean it ought to be.
>Want to know something neat about this? It could be implemented and
>not break any existing code! I know this is a very important consideration
>for any change to the language.
The language is not going to change in this respect.
--
- Paul J. Lucas
AT&T Bell Laboratories
Naperville, IL
Author: mcook@lna.logica.com (Michael Cook)
Date: Fri, 3 Jun 1994 22:40:47 GMT Raw View
>>>>> "affrunti" == Bob Affrunti <affrunti@orion.oac.uci.edu> writes:
affrunti> Why do default arguments have to follow the required arguments?
affrunti> Why couldn't you have something like:
affrunti> x.afrunction( ,2,,4 );
I think bs talks about this in D&E.
Among other problems, he says something about it being too subtle.
Michael.
Author: haydens@wayback.atc.ll.mit.edu (Hayden Schultz x3685 )
Date: 04 Jun 1994 03:01:56 GMT Raw View
>>>>> "Bob" == Bob Affrunti <affrunti@orion.oac.uci.edu> writes:
Bob> Why couldn't you have something like:
Bob> x.afunction( ,2,3,4 ); x.afrunction( ,2,,4 );
Well, for one thing there is an operator,(). So what would the above
syntax mean? Trouble for both the programmer and the compiler
writer. I think that anyone who writes code like afunction(a,(b,c),c)
should be taken out and shot, but that's valid C++ (and C) code, which
would be broken or very difficult to interpret. Plus, it would be one
more break with C syntax for no real gain in functionality.
Hayden
--
Hayden Schultz
haydens@ll.mit.edu
MIT Lincoln Lab
244 Wood St.
Lexington, MA, 02173
(617) 981-3685
Author: mat@mole-end.matawan.nj.us
Date: Sat, 4 Jun 1994 16:44:08 GMT Raw View
In article <pjl.770668670@graceland.att.com>, pjl@graceland.att.com (Paul J. Lucas) writes:
> In <affrunti.770665780@orion.oac.uci.edu> affrunti@orion.oac.uci.edu (Bob Affrunti) writes:
> >Why do default arguments have to follow the required arguments?
> >Why couldn't you have something like:
..
> >x.afunction( 1,2,3,4 );
> >x.afunction( ,2,3,4 );
> >x.afrunction( ,2,,4 );
..
> >I am sure that it has something to do with implementation and
> >figuring out which function to call if they are overloaded, ...
> It's not a technical problem. Just because something`n can be
> done doesn't mean it ought to be.
>
> >Want to know something neat about this? ...
I used a language where this was allowed. Under HP3000 FORTRAN, calls
made into the system `intrinsics' followed the calling conventions for
that system's implementation language, and that meant using defaulted
intermediate args.
You don't want to know the sort of mess we had trying to be sure of what
we meant by
call fgnxwyyr( abcds,,, 1024,, 70, 60,,, OUPUT,,, DEL )
The problem with _having_ this facility is that someone will start
to _use_ it ...
--
(This man's opinions are his own.)
From mole-end Mark Terribile
mat@mole-end.matawan.nj.us, Somewhere in Matawan, NJ
(Training and consulting in C, C++, UNIX, etc.)