Topic: Default argument, simple naive question


Author: shepherd@debussy.sbi.com (Marc Shepherd)
Date: 25 Jul 1994 12:20:49 GMT
Raw View
ldh@cs.brown.edu (Laurent Hasson) writes:
>
>>Let's say i have the following function:
>>  BOOL TruthTeller(Prop* p, int Level=10, int Efficiency=100);
[snip]...
>> Wouldn't it be easier, and harmless, to do:
>
>>    TruthTeller(P1,,y);
>

In "Design & Evolution of C++," Stroustrup gives a fairly convincing
defense of why this syntax was not allowed in C++.

Basically, his argument is that it would entice people into designing
functions with long argument lists, and that is not a coding style we
want to promote.  Bjarne feels that very few functions should take more
than two or three parameters.  Furthermore, he feels that there are
always better options available than a cryptic syntax like:

 TruthTeller(P1,,y);

One option is to make Level and Efficiency classes in their own right.
Then, TruthTeller can be overloaded to allow the different argument-passing
options that Mr. Hansson is looking for.  (This has the added benefit
that if someone accidentally passes Efficiency as the 2nd argument and
Level as the 3rd, the compiler will catch the mistake!)

---
Marc Shepherd
Salomon Brothers Inc
mshepherd@mhfl.sbi.com  The opinions I express are no one's but mine!